47 self.__calltips = None |
47 self.__calltips = None |
48 |
48 |
49 self.__methodMapping = { |
49 self.__methodMapping = { |
50 "CompletionsResult": self.__processCompletionsResult, |
50 "CompletionsResult": self.__processCompletionsResult, |
51 "CallTipsResult": self.__processCallTipsResult, |
51 "CallTipsResult": self.__processCallTipsResult, |
|
52 |
|
53 "ClientException": self.__processClientException, |
52 } |
54 } |
53 |
55 |
54 # Python 2 |
56 # Python 2 |
55 interpreter = Preferences.getDebugger("PythonInterpreter") |
57 self.__ensureActive("Python2") |
56 self.__startCodeAssistClient(interpreter, "Python2") |
|
57 |
58 |
58 # Python 3 |
59 # Python 3 |
59 interpreter = Preferences.getDebugger("Python3Interpreter") |
60 self.__ensureActive("Python3") |
60 self.__startCodeAssistClient(interpreter, "Python3") |
|
61 |
61 |
62 def __updateEditorLanguageMapping(self): |
62 def __updateEditorLanguageMapping(self): |
63 """ |
63 """ |
64 Private method to update the editor language to connection mapping. |
64 Private method to update the editor language to connection mapping. |
65 """ |
65 """ |
109 line, index = editor.getCursorPosition() |
109 line, index = editor.getCursorPosition() |
110 source = editor.text() |
110 source = editor.text() |
111 offset = len("".join(source.splitlines(True)[:line])) + index |
111 offset = len("".join(source.splitlines(True)[:line])) + index |
112 maxfixes = self.__plugin.getPreferences("MaxFixes") |
112 maxfixes = self.__plugin.getPreferences("MaxFixes") |
113 |
113 |
|
114 self.__ensureActive(idString) |
114 self.sendJson("getCompletions", { |
115 self.sendJson("getCompletions", { |
115 "FileName": filename, |
116 "FileName": filename, |
116 "Source": source, |
117 "Source": source, |
117 "Offset": offset, |
118 "Offset": offset, |
118 "MaxFixes": maxfixes, |
119 "MaxFixes": maxfixes, |
162 source = editor.text() |
163 source = editor.text() |
163 line, index = editor.lineIndexFromPosition(pos) |
164 line, index = editor.lineIndexFromPosition(pos) |
164 offset = len("".join(source.splitlines(True)[:line])) + index |
165 offset = len("".join(source.splitlines(True)[:line])) + index |
165 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") |
166 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") |
166 |
167 |
|
168 self.__ensureActive(idString) |
167 self.sendJson("getCallTips", { |
169 self.sendJson("getCallTips", { |
168 "FileName": filename, |
170 "FileName": filename, |
169 "Source": source, |
171 "Source": source, |
170 "Offset": offset, |
172 "Offset": offset, |
171 "MaxFixes": maxfixes, |
173 "MaxFixes": maxfixes, |
205 if editor is not None: |
207 if editor is not None: |
206 language = editor.getLanguage() |
208 language = editor.getLanguage() |
207 if language in self.__editorLanguageMapping: |
209 if language in self.__editorLanguageMapping: |
208 idString = self.__editorLanguageMapping[language] |
210 idString = self.__editorLanguageMapping[language] |
209 |
211 |
|
212 self.__ensureActive(idString) |
210 self.sendJson("reportChanged", { |
213 self.sendJson("reportChanged", { |
211 "FileName": filename, |
214 "FileName": filename, |
212 "OldSource": oldSource, |
215 "OldSource": oldSource, |
213 }, idString=idString) |
216 }, idString=idString) |
214 |
217 |
225 @param params dictionary with method specific parameters |
228 @param params dictionary with method specific parameters |
226 @type dict |
229 @type dict |
227 """ |
230 """ |
228 self.__methodMapping[method](params) |
231 self.__methodMapping[method](params) |
229 |
232 |
|
233 def __processClientException(self, params): |
|
234 """ |
|
235 Private method to handle exceptions of the refactoring client. |
|
236 |
|
237 @param params dictionary containing the exception data |
|
238 @type dict |
|
239 """ |
|
240 if params["ExceptionType"] == "ProtocolError": |
|
241 self.__ui.appendToStderr( |
|
242 self.tr("""The data received from the code assist""" |
|
243 """ server could not be decoded. Please report""" |
|
244 """ this issue with the received data to the""" |
|
245 """ eric bugs email address.\n""" |
|
246 """Error: {0}\n""" |
|
247 """Data: {1}\n""").format( |
|
248 params["ExceptionValue"], |
|
249 params["ProtocolData"])) |
|
250 else: |
|
251 self.__ui.appendToStderr( |
|
252 self.tr("An exception happened in the code assist" |
|
253 " client. Please report it to the eric bugs" |
|
254 " email address.\n" |
|
255 "Exception: {0}\n" |
|
256 "Value: {1}\n" |
|
257 "Traceback: {2}\n").format( |
|
258 params["ExceptionType"], |
|
259 params["ExceptionValue"], |
|
260 params["Traceback"])) |
|
261 |
230 def __startCodeAssistClient(self, interpreter, idString): |
262 def __startCodeAssistClient(self, interpreter, idString): |
231 """ |
263 """ |
232 Private method to start the code assist client with the given |
264 Private method to start the code assist client with the given |
233 interpreter. |
265 interpreter. |
234 |
266 |
235 @param interpreter interpreter to be used for the code assist client |
267 @param interpreter interpreter to be used for the code assist client |
236 @type str |
268 @type str |
237 @param idString id of the client to be started |
269 @param idString id of the client to be started |
238 @type str |
270 @type str |
239 """ |
271 @return flag indicating a successful start of the client |
|
272 @rtype bool |
|
273 """ |
|
274 ok = False |
|
275 |
240 if interpreter: |
276 if interpreter: |
241 client = os.path.join(os.path.dirname(__file__), |
277 client = os.path.join(os.path.dirname(__file__), |
242 "CodeAssistClient.py") |
278 "CodeAssistClient.py") |
243 ok = self.startClient(interpreter, client, |
279 ok = self.startClient(interpreter, client, |
244 [Globals.getConfigDir()], |
280 [Globals.getConfigDir()], |
245 idString=idString) |
281 idString=idString) |
246 if not ok: |
282 if not ok: |
247 self.__ui.appendToStderr(self.tr( |
283 self.__ui.appendToStderr(self.tr( |
248 "'{0}' is not supported because the configured interpreter" |
284 "'{0}' is not supported because the configured interpreter" |
249 " could not be started." |
285 " could not be started.\n" |
250 ).format(idString)) |
286 ).format(idString)) |
251 else: |
287 else: |
252 self.__ui.appendToStderr(self.tr( |
288 self.__ui.appendToStderr(self.tr( |
253 "'{0}' is not supported because no suitable interpreter is" |
289 "'{0}' is not supported because no suitable interpreter is" |
254 " configured." |
290 " configured.\n" |
255 ).format(idString)) |
291 ).format(idString)) |
|
292 |
|
293 return ok |
|
294 |
|
295 def __ensureActive(self, idString): |
|
296 """ |
|
297 Private method to ensure, that the requested client is active. |
|
298 |
|
299 A non-active client will be started. |
|
300 |
|
301 @return flag indicating an active client |
|
302 @rtype bool |
|
303 """ |
|
304 ok = idString in self.connectionNames() |
|
305 if not ok: |
|
306 # client is not running |
|
307 if idString == "Python2": |
|
308 # Python 2 |
|
309 interpreter = Preferences.getDebugger("PythonInterpreter") |
|
310 ok = self.__startCodeAssistClient(interpreter, "Python2") |
|
311 elif idString == "Python3": |
|
312 # Python 3 |
|
313 interpreter = Preferences.getDebugger("Python3Interpreter") |
|
314 ok = self.__startCodeAssistClient(interpreter, "Python3") |
|
315 return ok |
256 |
316 |
257 @pyqtSlot() |
317 @pyqtSlot() |
258 def handleNewConnection(self): |
318 def handleNewConnection(self): |
259 """ |
319 """ |
260 Public slot for new incoming connections from a client. |
320 Public slot for new incoming connections from a client. |