RefactoringRope/CodeAssistServer.py

changeset 293
dd1c7ed6d880
parent 291
da88cb84ae30
child 294
78e4a6823a98
equal deleted inserted replaced
292:3ead66c44f3f 293:dd1c7ed6d880
80 self.__methodMapping = { 80 self.__methodMapping = {
81 "Config": self.__setConfig, 81 "Config": self.__setConfig,
82 "CompletionsResult": self.__processCompletionsResult, 82 "CompletionsResult": self.__processCompletionsResult,
83 "CallTipsResult": self.__processCallTipsResult, 83 "CallTipsResult": self.__processCallTipsResult,
84 "DocumentationResult": self.__processDocumentationResult, 84 "DocumentationResult": self.__processDocumentationResult,
85 "GotoDefinitionResult": self.__gotoDefinitionResult,
85 86
86 "ClientException": self.__processClientException, 87 "ClientException": self.__processClientException,
87 } 88 }
88 89
89 self.__typeMapping = { 90 self.__typeMapping = {
101 # Python 2 102 # Python 2
102 self.__ensureActive("Python2") 103 self.__ensureActive("Python2")
103 104
104 # Python 3 105 # Python 3
105 self.__ensureActive("Python3") 106 self.__ensureActive("Python3")
107
108 def setAsyncCompletions(self, asynchronous):
109 """
110 Public method to set the asynchronous completions flag.
111
112 @param asynchronous flag indicating asynchronous completions
113 @type bool
114 """
115 self.__asyncCompletions = asynchronous
106 116
107 def __updateEditorLanguageMapping(self): 117 def __updateEditorLanguageMapping(self):
108 """ 118 """
109 Private method to update the editor language to connection mapping. 119 Private method to update the editor language to connection mapping.
110 """ 120 """
237 @param context flag indicating to autocomplete a context 247 @param context flag indicating to autocomplete a context
238 @type bool 248 @type bool
239 @return list of possible completions 249 @return list of possible completions
240 @rtype list of str 250 @rtype list of str
241 """ 251 """
252 if not self.__plugin.getPreferences("CodeAssistEnabled"):
253 return []
254
242 # reset the completions buffer 255 # reset the completions buffer
243 self.__completions = None 256 self.__completions = None
244 257
245 if not self.__idString(editor): 258 if not self.__idString(editor):
246 return [] 259 return []
268 @param context flag indicating to autocomplete a context 281 @param context flag indicating to autocomplete a context
269 @type bool 282 @type bool
270 @param acText text to be completed 283 @param acText text to be completed
271 @type str 284 @type str
272 """ 285 """
286 if not self.__plugin.getPreferences("CodeAssistEnabled"):
287 return
288
273 idString = self.__idString(editor) 289 idString = self.__idString(editor)
274 if not idString: 290 if not idString:
275 return 291 return
276 292
277 filename = editor.getFileName() 293 filename = editor.getFileName()
330 @param commas minimum number of commas contained in the calltip 346 @param commas minimum number of commas contained in the calltip
331 @type int 347 @type int
332 @return list of possible calltips 348 @return list of possible calltips
333 @rtype list of str 349 @rtype list of str
334 """ 350 """
351 if not self.__plugin.getPreferences("CodeAssistCalltipsEnabled"):
352 return []
353
335 # reset the calltips buffer 354 # reset the calltips buffer
336 self.__calltips = None 355 self.__calltips = None
337 356
338 idString = self.__idString(editor) 357 idString = self.__idString(editor)
339 if not idString: 358 if not idString:
482 msg = self.tr("No documentation available.") 501 msg = self.tr("No documentation available.")
483 self.__documentationViewer.documentationReady( 502 self.__documentationViewer.documentationReady(
484 msg, isDocWarning=True) 503 msg, isDocWarning=True)
485 else: 504 else:
486 self.__documentationViewer.documentationReady(docu) 505 self.__documentationViewer.documentationReady(docu)
506
507 def gotoDefinition(self, editor):
508 """
509 Public slot to find the definition for the word at the cursor position
510 and go to it.
511
512 Note: This is executed upon a mouse click sequence.
513
514 @param editor reference to the calling editor
515 @type QScintilla.Editor.Editor
516 """
517 if not self.__plugin.getPreferences("MouseClickEnabled"):
518 return
519
520 idString = self.__idString(editor)
521 if not idString:
522 return
523
524 filename = editor.getFileName()
525 source = editor.text()
526 line, index = editor.getCursorPosition()
527 offset = len("".join(source.splitlines(True)[:line])) + index
528
529 self.__ensureActive(idString)
530 self.sendJson("gotoDefinition", {
531 "FileName": filename,
532 "Offset": offset,
533 "Source": editor.text(),
534 "SysPath": sys.path,
535 }, idString=idString)
536
537 def __gotoDefinitionResult(self, result):
538 """
539 Private method to handle the "Goto Definition" result sent by
540 the client.
541
542 @param result dictionary containing the result data
543 @type dict
544 """
545 if "Error" not in result:
546 # ignore errors silently
547 if "Location" in result:
548 location = result["Location"]
549 try:
550 self.__vm.openSourceFile(
551 location["ModulePath"], location["Line"], addNext=True)
552 except TypeError:
553 # backward compatibility; <= 17.03
554 self.__vm.openSourceFile(
555 location["ModulePath"], location["Line"], next=True)
556 else:
557 e5App().getObject("UserInterface").statusBar().showMessage(
558 self.tr('Code Assist: No definition found'), 5000)
487 559
488 ####################################################################### 560 #######################################################################
489 ## Methods below handle the network connection 561 ## Methods below handle the network connection
490 ####################################################################### 562 #######################################################################
491 563
795 867
796 ####################################################################### 868 #######################################################################
797 ## Methods below handle setting/unsetting the hook methods 869 ## Methods below handle setting/unsetting the hook methods
798 ####################################################################### 870 #######################################################################
799 871
800 def connectEditor(self, editor): 872 ## def connectEditor(self, editor):
801 """ 873 ## """
802 Public method to connect an editor. 874 ## Public method to connect an editor.
803 875 ##
804 @param editor reference to the editor 876 ## @param editor reference to the editor
805 @type QScintilla.Editor.Editor 877 ## @type QScintilla.Editor.Editor
806 """ 878 ## """
807 # TODO: special treatment for project files 879 ## # TODO: special treatment for project files
808 if self.isSupportedLanguage(editor.getLanguage()): 880 ## if self.isSupportedLanguage(editor.getLanguage()):
809 if self.__plugin.getPreferences("CodeAssistEnabled") and \ 881 ## if self.__plugin.getPreferences("CodeAssistEnabled") and \
810 editor.getCompletionListHook("rope") is None: 882 ## editor.getCompletionListHook("rope") is None:
811 self.__setAutoCompletionHook(editor) 883 ## self.__setAutoCompletionHook(editor)
812 if self.__plugin.getPreferences("CodeAssistCalltipsEnabled") and \ 884 ## if self.__plugin.getPreferences("CodeAssistCalltipsEnabled") and \
813 editor.getCallTipHook("rope") is None: 885 ## editor.getCallTipHook("rope") is None:
814 self.__setCalltipsHook(editor) 886 ## self.__setCalltipsHook(editor)
815 else: 887 ## else:
816 self.disconnectEditor(editor) 888 ## self.disconnectEditor(editor)
817 889 ##
818 def disconnectEditor(self, editor): 890 ## def disconnectEditor(self, editor):
819 """ 891 ## """
820 Public method to disconnect an editor. 892 ## Public method to disconnect an editor.
821 893 ##
822 @param editor reference to the editor 894 ## @param editor reference to the editor
823 @type QScintilla.Editor.Editor 895 ## @type QScintilla.Editor.Editor
824 """ 896 ## """
825 if editor.getCompletionListHook("rope"): 897 ## if editor.getCompletionListHook("rope"):
826 self.__unsetAutoCompletionHook(editor) 898 ## self.__unsetAutoCompletionHook(editor)
827 if editor.getCallTipHook("rope"): 899 ## if editor.getCallTipHook("rope"):
828 self.__unsetCalltipsHook(editor) 900 ## self.__unsetCalltipsHook(editor)
829 901 ##
830 def __setAutoCompletionHook(self, editor): 902 ## def __setAutoCompletionHook(self, editor):
831 """ 903 ## """
832 Private method to set the auto-completion hook. 904 ## Private method to set the auto-completion hook.
833 905 ##
834 @param editor reference to the editor 906 ## @param editor reference to the editor
835 @type QScintilla.Editor.Editor 907 ## @type QScintilla.Editor.Editor
836 """ 908 ## """
837 try: 909 ## try:
838 editor.addCompletionListHook("rope", self.requestCompletions, True) 910 ## editor.addCompletionListHook("rope", self.requestCompletions, True)
839 self.__asyncCompletions = True 911 ## self.__asyncCompletions = True
840 except TypeError: 912 ## except TypeError:
841 # backward compatibility for eric6 before 17.11 913 ## # backward compatibility for eric6 before 17.11
842 editor.addCompletionListHook("rope", self.getCompletions) 914 ## editor.addCompletionListHook("rope", self.getCompletions)
843 self.__asyncCompletions = False 915 ## self.__asyncCompletions = False
844 916 ##
845 def __unsetAutoCompletionHook(self, editor): 917 ## def __unsetAutoCompletionHook(self, editor):
846 """ 918 ## """
847 Private method to unset the auto-completion hook. 919 ## Private method to unset the auto-completion hook.
848 920 ##
849 @param editor reference to the editor 921 ## @param editor reference to the editor
850 @type QScintilla.Editor.Editor 922 ## @type QScintilla.Editor.Editor
851 """ 923 ## """
852 editor.removeCompletionListHook("rope") 924 ## editor.removeCompletionListHook("rope")
853 925 ##
854 def __setCalltipsHook(self, editor): 926 ## def __setCalltipsHook(self, editor):
855 """ 927 ## """
856 Private method to set the calltip hook. 928 ## Private method to set the calltip hook.
857 929 ##
858 @param editor reference to the editor 930 ## @param editor reference to the editor
859 @type QScintilla.Editor.Editor 931 ## @type QScintilla.Editor.Editor
860 """ 932 ## """
861 editor.addCallTipHook("rope", self.getCallTips) 933 ## editor.addCallTipHook("rope", self.getCallTips)
862 934 ##
863 def __unsetCalltipsHook(self, editor): 935 ## def __unsetCalltipsHook(self, editor):
864 """ 936 ## """
865 Private method to unset the calltip hook. 937 ## Private method to unset the calltip hook.
866 938 ##
867 @param editor reference to the editor 939 ## @param editor reference to the editor
868 @type QScintilla.Editor.Editor 940 ## @type QScintilla.Editor.Editor
869 """ 941 ## """
870 editor.removeCallTipHook("rope") 942 ## editor.removeCallTipHook("rope")

eric ide

mercurial