RefactoringRope/CodeAssistServer.py

branch
server_client_variant
changeset 199
ae2ad82725b0
parent 198
898d8b4187de
child 200
1584892147ef
diff -r 898d8b4187de -r ae2ad82725b0 RefactoringRope/CodeAssistServer.py
--- a/RefactoringRope/CodeAssistServer.py	Wed Sep 27 18:25:08 2017 +0200
+++ b/RefactoringRope/CodeAssistServer.py	Wed Sep 27 18:42:35 2017 +0200
@@ -50,6 +50,7 @@
         
         self.__methodMapping = {
             "CompletionsResult": self.__processCompletionsResult,
+            "CallTipsResult": self.__processCallTipsResult,
         }
         
         # Python 2
@@ -140,39 +141,58 @@
         else:
             self.__completions = result["Completions"]
     
-    # TODO: port this to the distributed variant
     def getCallTips(self, pos, editor):
         """
         Public method to calculate calltips.
         
-        @param pos position in the text for the calltip (integer)
+        @param pos position in the text for the calltip
+        @type int
         @param editor reference to the editor object, that called this method
-            QScintilla.Editor)
-        @return list of possible calltips (list of strings)
+        @type QScintilla.Editor
+        @return list of possible calltips
+        @rtype list of str
         """
-        print("rope: getCallTips")
-        return []
-##        filename = editor.getFileName()
-##        if filename:
-##            resource = rope.base.libutils.path_to_resource(
-##                self.__project, filename)
-##        else:
-##            resource = None
-##        source = editor.text()
-##        maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes")
-##        try:
-##            line, index = editor.lineIndexFromPosition(pos)
-##            offset = len("".join(source.splitlines(True)[:line])) + index
-##            cts = rope.contrib.codeassist.get_calltip(
-##                self.__project, source, offset, resource, maxfixes=maxfixes,
-##                remove_self=True)
-##            if cts is not None:
-##                cts = [cts]
-##            else:
-##                cts = []
-##        except Exception:
-##            cts = []
-##        return cts
+        # reset the calltips buffer
+        self.__calltips = None
+        
+        language = editor.getLanguage()
+        if language not in self.__editorLanguageMapping:
+            return []
+        idString = self.__editorLanguageMapping[language]
+        
+        filename = editor.getFileName()
+        source = editor.text()
+        line, index = editor.lineIndexFromPosition(pos)
+        offset = len("".join(source.splitlines(True)[:line])) + index
+        maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes")
+        
+        self.sendJson("getCallTips", {
+            "FileName": filename,
+            "Source": source,
+            "Offset": offset,
+            "MaxFixes": maxfixes,
+        }, idString=idString)
+        
+        # emulate the synchronous behaviour
+        timer = QTimer()
+        timer.setSingleShot(True)
+        timer.start(5000)           # 5s timeout
+        while self.__calltips is None and timer.isActive():
+            QCoreApplication.processEvents()
+        
+        return [] if self.__calltips is None else self.__calltips
+    
+    def __processCallTipsResult(self, result):
+        """
+        Private method to process the calltips sent by the client.
+        
+        @param result dictionary containg the result sent by the client
+        @type dict
+        """
+        if "Error" in result:
+            self.__calltips = []
+        else:
+            self.__calltips = result["CallTips"]
     
     # TODO: port this to the distributed variant
     def reportChanged(self, filename, oldSource):

eric ide

mercurial