RefactoringRope/CodeAssistServer.py

Thu, 05 Oct 2017 19:24:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 05 Oct 2017 19:24:14 +0200
branch
server_client_variant
changeset 209
c1dce8630555
parent 203
c38750e1bafd
child 212
f05681349336
permissions
-rw-r--r--

Improved handling of died connections/processes.

100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
147
3f8a995f6e49 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 144
diff changeset
3 # Copyright (c) 2008 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the autocompletion interface to rope.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
10 from __future__ import unicode_literals
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
11
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
14 from PyQt5.QtCore import pyqtSlot, QCoreApplication, QTimer
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
15
200
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
16 from E5Gui.E5Application import e5App
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
17
202
a111134b5dc7 Started correcting the source code documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 200
diff changeset
18 from .JsonServer import JsonServer
193
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
19
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
20 import Globals
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
21 import Preferences
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
22
118
d242ba11a04c Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 106
diff changeset
23
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
24 class CodeAssistServer(JsonServer):
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Class implementing the autocompletion interface to rope.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
118
d242ba11a04c Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 106
diff changeset
28 def __init__(self, plugin, parent=None):
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param plugin reference to the plugin object
193
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
33 @type RefactoringRopePlugin
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
34 @param parent parent
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
35 @type QObject
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
37 super(CodeAssistServer, self).__init__(
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
38 "CodeAssistServer", multiplex=True, parent=parent)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__plugin = plugin
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
41 self.__ui = parent
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
42
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
43 self.__editorLanguageMapping = {}
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
44
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
45 # attributes to store the resuls of the client side
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
46 self.__completions = None
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
47 self.__calltips = None
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
48
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
49 self.__methodMapping = {
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
50 "CompletionsResult": self.__processCompletionsResult,
199
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
51 "CallTipsResult": self.__processCallTipsResult,
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
52
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
53 "ClientException": self.__processClientException,
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
54 }
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
55
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
56 # Python 2
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
57 self.__ensureActive("Python2")
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
58
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
59 # Python 3
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
60 self.__ensureActive("Python3")
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
62 def __updateEditorLanguageMapping(self):
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
63 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
64 Private method to update the editor language to connection mapping.
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
65 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
66 self.__editorLanguageMapping = {}
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
67 for name in self.connectionNames():
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
68 if name == "Python2":
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
69 self.__editorLanguageMapping.update({
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
70 "Python": "Python2",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
71 "Python2": "Python2",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
72 "Pygments|Python": "Python2",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
73 })
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
74 elif name == "Python3":
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
75 self.__editorLanguageMapping.update({
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
76 "Python3": "Python3",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
77 "Pygments|Python 3": "Python3",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
78 })
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
79
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
80 def isSupportedLanguage(self, language):
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
81 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
82 Public method to check, if the given language is supported.
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
83
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
84 @param language editor programming language to check
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
85 @type str
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
86 @return flag indicating the support status
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
87 @rtype bool
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
88 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
89 return language in self.__editorLanguageMapping
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
90
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
91 def getCompletions(self, editor):
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 Public method to calculate the possible completions.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
95 @param editor reference to the editor object, that called this method
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
96 @type QScintilla.Editor
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
97 @return list of proposals
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
98 @rtype list of str
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
100 # reset the completions buffer
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
101 self.__completions = None
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
102
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
103 language = editor.getLanguage()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
104 if language not in self.__editorLanguageMapping:
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
105 return []
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
106 idString = self.__editorLanguageMapping[language]
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
107
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
108 filename = editor.getFileName()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
109 line, index = editor.getCursorPosition()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
110 source = editor.text()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
111 offset = len("".join(source.splitlines(True)[:line])) + index
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
112 maxfixes = self.__plugin.getPreferences("MaxFixes")
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
113
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
114 self.__ensureActive(idString)
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
115 self.sendJson("getCompletions", {
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
116 "FileName": filename,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
117 "Source": source,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
118 "Offset": offset,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
119 "MaxFixes": maxfixes,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
120 }, idString=idString)
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
121
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
122 # emulate the synchronous behaviour
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
123 timer = QTimer()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
124 timer.setSingleShot(True)
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
125 timer.start(5000) # 5s timeout
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
126 while self.__completions is None and timer.isActive():
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
127 QCoreApplication.processEvents()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
128
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
129 return [] if self.__completions is None else self.__completions
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
130
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
131 def __processCompletionsResult(self, result):
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
132 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
133 Private method to process the completions sent by the client.
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
134
202
a111134b5dc7 Started correcting the source code documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 200
diff changeset
135 @param result dictionary containing the result sent by the client
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
136 @type dict
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
137 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
138 if "Error" in result:
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
139 self.__completions = []
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
140 else:
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
141 self.__completions = result["Completions"]
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
143 def getCallTips(self, pos, editor):
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 Public method to calculate calltips.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
199
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
147 @param pos position in the text for the calltip
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
148 @type int
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
149 @param editor reference to the editor object, that called this method
199
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
150 @type QScintilla.Editor
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
151 @return list of possible calltips
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
152 @rtype list of str
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
199
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
154 # reset the calltips buffer
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
155 self.__calltips = None
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
156
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
157 language = editor.getLanguage()
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
158 if language not in self.__editorLanguageMapping:
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
159 return []
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
160 idString = self.__editorLanguageMapping[language]
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
161
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
162 filename = editor.getFileName()
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
163 source = editor.text()
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
164 line, index = editor.lineIndexFromPosition(pos)
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
165 offset = len("".join(source.splitlines(True)[:line])) + index
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
166 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes")
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
167
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
168 self.__ensureActive(idString)
199
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
169 self.sendJson("getCallTips", {
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
170 "FileName": filename,
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
171 "Source": source,
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
172 "Offset": offset,
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
173 "MaxFixes": maxfixes,
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
174 }, idString=idString)
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
175
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
176 # emulate the synchronous behaviour
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
177 timer = QTimer()
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
178 timer.setSingleShot(True)
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
179 timer.start(5000) # 5s timeout
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
180 while self.__calltips is None and timer.isActive():
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
181 QCoreApplication.processEvents()
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
182
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
183 return [] if self.__calltips is None else self.__calltips
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
184
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
185 def __processCallTipsResult(self, result):
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
186 """
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
187 Private method to process the calltips sent by the client.
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
188
202
a111134b5dc7 Started correcting the source code documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 200
diff changeset
189 @param result dictionary containing the result sent by the client
199
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
190 @type dict
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
191 """
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
192 if "Error" in result:
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
193 self.__calltips = []
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
194 else:
ae2ad82725b0 Implemented the distributed code assist calltips method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 198
diff changeset
195 self.__calltips = result["CallTips"]
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
196
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
197 def reportChanged(self, filename, oldSource):
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
198 """
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
199 Public slot to report some changed sources.
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
200
200
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
201 @param filename file name of the changed source
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
202 @type str
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
203 @param oldSource source code before the change
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
204 @type str
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
205 """
200
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
206 editor = e5App().getObject("ViewManager").getOpenEditor(filename)
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
207 if editor is not None:
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
208 language = editor.getLanguage()
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
209 if language in self.__editorLanguageMapping:
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
210 idString = self.__editorLanguageMapping[language]
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
211
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
212 self.__ensureActive(idString)
200
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
213 self.sendJson("reportChanged", {
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
214 "FileName": filename,
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
215 "OldSource": oldSource,
1584892147ef Implemented the distributed code assist "report changed" method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 199
diff changeset
216 }, idString=idString)
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
217
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
218 #######################################################################
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
219 ## Methods below handle the network connection
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
220 #######################################################################
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
221
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
222 def handleCall(self, method, params):
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
223 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
224 Public method to handle a method call from the client.
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
225
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
226 @param method requested method name
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
227 @type str
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
228 @param params dictionary with method specific parameters
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
229 @type dict
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
230 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
231 self.__methodMapping[method](params)
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
232
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
233 def __processClientException(self, params):
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
234 """
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
235 Private method to handle exceptions of the refactoring client.
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
236
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
237 @param params dictionary containing the exception data
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
238 @type dict
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
239 """
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
240 if params["ExceptionType"] == "ProtocolError":
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
241 self.__ui.appendToStderr(
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
242 self.tr("""The data received from the code assist"""
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
243 """ server could not be decoded. Please report"""
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
244 """ this issue with the received data to the"""
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
245 """ eric bugs email address.\n"""
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
246 """Error: {0}\n"""
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
247 """Data: {1}\n""").format(
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
248 params["ExceptionValue"],
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
249 params["ProtocolData"]))
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
250 else:
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
251 self.__ui.appendToStderr(
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
252 self.tr("An exception happened in the code assist"
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
253 " client. Please report it to the eric bugs"
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
254 " email address.\n"
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
255 "Exception: {0}\n"
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
256 "Value: {1}\n"
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
257 "Traceback: {2}\n").format(
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
258 params["ExceptionType"],
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
259 params["ExceptionValue"],
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
260 params["Traceback"]))
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
261
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
262 def __startCodeAssistClient(self, interpreter, idString):
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
263 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
264 Private method to start the code assist client with the given
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
265 interpreter.
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
266
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
267 @param interpreter interpreter to be used for the code assist client
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
268 @type str
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
269 @param idString id of the client to be started
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
270 @type str
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
271 @return flag indicating a successful start of the client
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
272 @rtype bool
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
273 """
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
274 ok = False
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
275
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
276 if interpreter:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
277 client = os.path.join(os.path.dirname(__file__),
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
278 "CodeAssistClient.py")
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
279 ok = self.startClient(interpreter, client,
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
280 [Globals.getConfigDir()],
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
281 idString=idString)
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
282 if not ok:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
283 self.__ui.appendToStderr(self.tr(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
284 "'{0}' is not supported because the configured interpreter"
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
285 " could not be started.\n"
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
286 ).format(idString))
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
287 else:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
288 self.__ui.appendToStderr(self.tr(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
289 "'{0}' is not supported because no suitable interpreter is"
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
290 " configured.\n"
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
291 ).format(idString))
209
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
292
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
293 return ok
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
294
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
295 def __ensureActive(self, idString):
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
296 """
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
297 Private method to ensure, that the requested client is active.
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
298
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
299 A non-active client will be started.
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
300
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
301 @return flag indicating an active client
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
302 @rtype bool
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
303 """
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
304 ok = idString in self.connectionNames()
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
305 if not ok:
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
306 # client is not running
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
307 if idString == "Python2":
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
308 # Python 2
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
309 interpreter = Preferences.getDebugger("PythonInterpreter")
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
310 ok = self.__startCodeAssistClient(interpreter, "Python2")
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
311 elif idString == "Python3":
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
312 # Python 3
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
313 interpreter = Preferences.getDebugger("Python3Interpreter")
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
314 ok = self.__startCodeAssistClient(interpreter, "Python3")
c1dce8630555 Improved handling of died connections/processes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 203
diff changeset
315 return ok
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
316
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
317 @pyqtSlot()
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
318 def handleNewConnection(self):
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
319 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
320 Public slot for new incoming connections from a client.
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
321 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
322 super(CodeAssistServer, self).handleNewConnection()
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
323 self.__updateEditorLanguageMapping()
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
324
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
325 def activate(self):
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
326 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
327 Public method to activate the code assist server.
202
a111134b5dc7 Started correcting the source code documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 200
diff changeset
328
a111134b5dc7 Started correcting the source code documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 200
diff changeset
329 Note: This method provides for some growth potential.
a111134b5dc7 Started correcting the source code documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 200
diff changeset
330 Currently it is empty.
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
331 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
332 pass
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
333
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
334 def deactivate(self):
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
335 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
336 Public method to deactivate the code assist server.
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
337 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
338 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
339 Public method to shut down the code assist server.
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
340 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
341 self.stopAllClients()

eric ide

mercurial