46 self.__clientConfigs = {} |
47 self.__clientConfigs = {} |
47 self.__editors = {} |
48 self.__editors = {} |
48 |
49 |
49 self.__asyncCompletions = False |
50 self.__asyncCompletions = False |
50 |
51 |
|
52 self.__documentationViewer = None |
|
53 |
51 # attributes to store the resuls of the client side |
54 # attributes to store the resuls of the client side |
52 self.__completions = None |
55 self.__completions = None |
53 self.__calltips = None |
56 self.__calltips = None |
54 |
57 |
55 self.__methodMapping = { |
58 self.__methodMapping = { |
56 "Config": self.__setConfig, |
59 "Config": self.__setConfig, |
57 "CompletionsResult": self.__processCompletionsResult, |
60 "CompletionsResult": self.__processCompletionsResult, |
58 "CallTipsResult": self.__processCallTipsResult, |
61 "CallTipsResult": self.__processCallTipsResult, |
|
62 "DocumentationResult": self.__processDocumentationResult, |
59 |
63 |
60 "ClientException": self.__processClientException, |
64 "ClientException": self.__processClientException, |
61 } |
65 } |
62 |
66 |
63 # Python 2 |
67 # Python 2 |
170 Public method to calculate the possible completions. |
174 Public method to calculate the possible completions. |
171 |
175 |
172 Note: This is the synchronous variant for eric6 before 17.11. |
176 Note: This is the synchronous variant for eric6 before 17.11. |
173 |
177 |
174 @param editor reference to the editor object, that called this method |
178 @param editor reference to the editor object, that called this method |
175 @type QScintilla.Editor |
179 @type QScintilla.Editor.Editor |
176 @param context flag indicating to autocomplete a context |
180 @param context flag indicating to autocomplete a context |
177 @type bool |
181 @type bool |
178 @return list of possible completions |
182 @return list of possible completions |
179 @rtype list of str |
183 @rtype list of str |
180 """ |
184 """ |
202 |
206 |
203 Note: This is part of the asynchronous variant for eric6 17.11 and |
207 Note: This is part of the asynchronous variant for eric6 17.11 and |
204 later. |
208 later. |
205 |
209 |
206 @param editor reference to the editor object, that called this method |
210 @param editor reference to the editor object, that called this method |
207 @type QScintilla.Editor |
211 @type QScintilla.Editor.Editor |
208 @param context flag indicating to autocomplete a context |
212 @param context flag indicating to autocomplete a context |
209 @type bool |
213 @type bool |
210 @param acText text to be completed |
214 @param acText text to be completed |
211 @type str |
215 @type str |
212 """ |
216 """ |
226 "FileName": filename, |
230 "FileName": filename, |
227 "Source": source, |
231 "Source": source, |
228 "Offset": offset, |
232 "Offset": offset, |
229 "MaxFixes": maxfixes, |
233 "MaxFixes": maxfixes, |
230 "CompletionText": acText, |
234 "CompletionText": acText, |
|
235 "SysPath": sys.path, |
231 }, idString=idString) |
236 }, idString=idString) |
232 |
237 |
233 def __processCompletionsResult(self, result): |
238 def __processCompletionsResult(self, result): |
234 """ |
239 """ |
235 Private method to process the completions sent by the client. |
240 Private method to process the completions sent by the client. |
254 def getCallTips(self, editor, pos, commas): |
259 def getCallTips(self, editor, pos, commas): |
255 """ |
260 """ |
256 Public method to calculate calltips. |
261 Public method to calculate calltips. |
257 |
262 |
258 @param editor reference to the editor object, that called this method |
263 @param editor reference to the editor object, that called this method |
259 @type QScintilla.Editor |
264 @type QScintilla.Editor.Editor |
260 @param pos position in the text for the calltip |
265 @param pos position in the text for the calltip |
261 @type int |
266 @type int |
262 @param commas minimum number of commas contained in the calltip |
267 @param commas minimum number of commas contained in the calltip |
263 @type int |
268 @type int |
264 @return list of possible calltips |
269 @return list of possible calltips |
282 self.sendJson("getCallTips", { |
287 self.sendJson("getCallTips", { |
283 "FileName": filename, |
288 "FileName": filename, |
284 "Source": source, |
289 "Source": source, |
285 "Offset": offset, |
290 "Offset": offset, |
286 "MaxFixes": maxfixes, |
291 "MaxFixes": maxfixes, |
|
292 "SysPath": sys.path, |
287 }, idString=idString) |
293 }, idString=idString) |
288 |
294 |
289 # emulate the synchronous behaviour |
295 # emulate the synchronous behaviour |
290 timer = QTimer() |
296 timer = QTimer() |
291 timer.setSingleShot(True) |
297 timer.setSingleShot(True) |
325 self.__ensureActive(idString) |
331 self.__ensureActive(idString) |
326 self.sendJson("reportChanged", { |
332 self.sendJson("reportChanged", { |
327 "FileName": filename, |
333 "FileName": filename, |
328 "OldSource": oldSource, |
334 "OldSource": oldSource, |
329 }, idString=idString) |
335 }, idString=idString) |
|
336 |
|
337 def requestCodeDocumentation(self, editor): |
|
338 """ |
|
339 Public method to request source code documentation for the given |
|
340 editor. |
|
341 |
|
342 @param editor reference to the editor to get source code documentation |
|
343 for |
|
344 @type QScintilla.Editor.Editor |
|
345 """ |
|
346 language = editor.getLanguage() |
|
347 if language not in self.__editorLanguageMapping: |
|
348 return |
|
349 idString = self.__editorLanguageMapping[language] |
|
350 |
|
351 filename = editor.getFileName() |
|
352 source = editor.text() |
|
353 line, index = editor.getCursorPosition() |
|
354 offset = len("".join(source.splitlines(True)[:line])) + index |
|
355 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") |
|
356 |
|
357 offset = editor.positionBefore(offset) |
|
358 if editor.charAt(offset) == "(": |
|
359 offset = editor.positionBefore(offset) |
|
360 |
|
361 self.__ensureActive(idString) |
|
362 self.sendJson("getDocumentation", { |
|
363 "FileName": filename, |
|
364 "Source": source, |
|
365 "Offset": offset, |
|
366 "MaxFixes": maxfixes, |
|
367 "SysPath": sys.path, |
|
368 }, idString=idString) |
|
369 |
|
370 def __processDocumentationResult(self, result): |
|
371 """ |
|
372 Private method to process the documentation sent by the client. |
|
373 |
|
374 @param result dictionary containing the result sent by the client |
|
375 @type dict |
|
376 """ |
|
377 if "Error" not in result: |
|
378 documentationDict = result["DocumentationDict"] |
|
379 if "module" in documentationDict: |
|
380 documentationDict["note"] = \ |
|
381 self.tr("Present in {0} module").format( |
|
382 documentationDict["module"]) |
|
383 del documentationDict["module"] |
|
384 docu = documentationDict |
|
385 else: |
|
386 docu = None |
|
387 |
|
388 self.__documentationViewer.documentationReady(docu) |
330 |
389 |
331 ####################################################################### |
390 ####################################################################### |
332 ## Methods below handle the network connection |
391 ## Methods below handle the network connection |
333 ####################################################################### |
392 ####################################################################### |
334 |
393 |
442 self.__getConfigs() |
503 self.__getConfigs() |
443 |
504 |
444 def activate(self): |
505 def activate(self): |
445 """ |
506 """ |
446 Public method to activate the code assist server. |
507 Public method to activate the code assist server. |
447 |
508 """ |
448 Note: This method provides for some growth potential. |
509 try: |
449 Currently it is empty. |
510 self.__documentationViewer = self.__ui.documentationViewer() |
450 """ |
511 self.__documentationViewer.registerProvider( |
451 pass |
512 "rope", self.tr("Rope"), self.requestCodeDocumentation) |
|
513 except AttributeError: |
|
514 # eric6 before 17.11 doesn't have this |
|
515 pass |
452 |
516 |
453 def deactivate(self): |
517 def deactivate(self): |
454 """ |
518 """ |
455 Public method to deactivate the code assist server. |
519 Public method to deactivate the code assist server. |
456 """ |
520 """ |
457 """ |
521 """ |
458 Public method to shut down the code assist server. |
522 Public method to shut down the code assist server. |
459 """ |
523 """ |
|
524 if self.__documentationViewer is not None: |
|
525 self.__documentationViewer.unregisterProvider("rope") |
|
526 |
460 for idString in self.connectionNames(): |
527 for idString in self.connectionNames(): |
461 self.sendJson("closeProject", {}, flush=True, idString=idString) |
528 self.sendJson("closeProject", {}, flush=True, idString=idString) |
462 |
529 |
463 self.stopAllClients() |
530 self.stopAllClients() |
464 |
531 |
469 def connectEditor(self, editor): |
536 def connectEditor(self, editor): |
470 """ |
537 """ |
471 Public method to connect an editor. |
538 Public method to connect an editor. |
472 |
539 |
473 @param editor reference to the editor |
540 @param editor reference to the editor |
474 @type QScintilla.Editor |
541 @type QScintilla.Editor.Editor |
475 """ |
542 """ |
476 if self.isSupportedLanguage(editor.getLanguage()): |
543 if self.isSupportedLanguage(editor.getLanguage()): |
477 if self.__plugin.getPreferences("CodeAssistEnabled") and \ |
544 if self.__plugin.getPreferences("CodeAssistEnabled") and \ |
478 editor.getCompletionListHook("rope") is None: |
545 editor.getCompletionListHook("rope") is None: |
479 self.__setAutoCompletionHook(editor) |
546 self.__setAutoCompletionHook(editor) |
486 def disconnectEditor(self, editor): |
553 def disconnectEditor(self, editor): |
487 """ |
554 """ |
488 Public method to disconnect an editor. |
555 Public method to disconnect an editor. |
489 |
556 |
490 @param editor reference to the editor |
557 @param editor reference to the editor |
491 @type QScintilla.Editor |
558 @type QScintilla.Editor.Editor |
492 """ |
559 """ |
493 if editor.getCompletionListHook("rope"): |
560 if editor.getCompletionListHook("rope"): |
494 self.__unsetAutoCompletionHook(editor) |
561 self.__unsetAutoCompletionHook(editor) |
495 if editor.getCallTipHook("rope"): |
562 if editor.getCallTipHook("rope"): |
496 self.__unsetCalltipsHook(editor) |
563 self.__unsetCalltipsHook(editor) |
498 def __setAutoCompletionHook(self, editor): |
565 def __setAutoCompletionHook(self, editor): |
499 """ |
566 """ |
500 Private method to set the auto-completion hook. |
567 Private method to set the auto-completion hook. |
501 |
568 |
502 @param editor reference to the editor |
569 @param editor reference to the editor |
503 @type QScintilla.Editor |
570 @type QScintilla.Editor.Editor |
504 """ |
571 """ |
505 try: |
572 try: |
506 editor.addCompletionListHook("rope", self.requestCompletions, |
573 editor.addCompletionListHook("rope", self.requestCompletions, |
507 async=True) |
574 async=True) |
508 self.__asyncCompletions = True |
575 self.__asyncCompletions = True |
514 def __unsetAutoCompletionHook(self, editor): |
581 def __unsetAutoCompletionHook(self, editor): |
515 """ |
582 """ |
516 Private method to unset the auto-completion hook. |
583 Private method to unset the auto-completion hook. |
517 |
584 |
518 @param editor reference to the editor |
585 @param editor reference to the editor |
519 @type QScintilla.Editor |
586 @type QScintilla.Editor.Editor |
520 """ |
587 """ |
521 editor.removeCompletionListHook("rope") |
588 editor.removeCompletionListHook("rope") |
522 |
589 |
523 def __setCalltipsHook(self, editor): |
590 def __setCalltipsHook(self, editor): |
524 """ |
591 """ |
525 Private method to set the calltip hook. |
592 Private method to set the calltip hook. |
526 |
593 |
527 @param editor reference to the editor |
594 @param editor reference to the editor |
528 @type QScintilla.Editor |
595 @type QScintilla.Editor.Editor |
529 """ |
596 """ |
530 editor.addCallTipHook("rope", self.getCallTips) |
597 editor.addCallTipHook("rope", self.getCallTips) |
531 |
598 |
532 def __unsetCalltipsHook(self, editor): |
599 def __unsetCalltipsHook(self, editor): |
533 """ |
600 """ |
534 Private method to unset the calltip hook. |
601 Private method to unset the calltip hook. |
535 |
602 |
536 @param editor reference to the editor |
603 @param editor reference to the editor |
537 @type QScintilla.Editor |
604 @type QScintilla.Editor.Editor |
538 """ |
605 """ |
539 editor.removeCallTipHook("rope") |
606 editor.removeCallTipHook("rope") |
540 |
607 |
541 # TODO: add method to edit the codeassist python2 and 3 config files |
608 # TODO: add method to edit the codeassist python2 and 3 config files |