RefactoringRope/CodeAssistClient.py

changeset 293
dd1c7ed6d880
parent 291
da88cb84ae30
child 302
2e853e2f2430
--- a/RefactoringRope/CodeAssistClient.py	Sun Nov 11 19:43:10 2018 +0100
+++ b/RefactoringRope/CodeAssistClient.py	Sun Nov 11 19:43:56 2018 +0100
@@ -30,6 +30,8 @@
     """
     Class implementing the code assist client interface to rope.
     """
+    IdProject = "Project"
+    
     def __init__(self, host, port, idString, projectPath):
         """
         Constructor
@@ -53,6 +55,7 @@
             "getCompletions": self.__getCompletions,
             "getCallTips": self.__getCallTips,
             "getDocumentation": self.__getDocumentation,
+            "gotoDefinition": self.__gotoDefinition,
             "reportChanged": self.__reportChanged,
         }
         
@@ -228,7 +231,8 @@
         offset = params["Offset"]
         maxfixes = params["MaxFixes"]
         
-        self.__project.prefs.set("python_path", params["SysPath"])
+        if not self.__id == CodeAssistClient.IdProject:
+            self.__project.prefs.set("python_path", params["SysPath"])
         if filename:
             resource = rope.base.libutils.path_to_resource(
                 self.__project, filename)
@@ -374,6 +378,46 @@
         
         return typ, name
     
+    def __gotoDefinition(self, params):
+        """
+        Private method to handle the Goto Definition action.
+        
+        @param params dictionary containing the method parameters sent by
+            the server
+        @type dict
+        """
+        import rope.base.libutils
+        
+        filename = params["FileName"]
+        offset = params["Offset"]
+        source = params["Source"]
+        
+        self.__project.prefs.set("python_path", params["SysPath"])
+        if filename:
+            resource = rope.base.libutils.path_to_resource(
+                self.__project, filename)
+        else:
+            resource = None
+        
+        errorDict = {}
+        result = {}
+        
+        import rope.contrib.findit
+        try:
+            location = rope.contrib.findit.find_definition(
+                self.__project, source, offset, resource)
+        except Exception as err:
+            errorDict = self.__handleRopeError(err)
+        
+        if location is not None:
+            result["Location"] = {
+                "ModulePath": location.resource.real_path,
+                "Line": location.lineno,
+            }
+        result.update(errorDict)
+        
+        self.sendJson("GotoDefinitionResult", result)
+    
     def __reportChanged(self, params):
         """
         Private method to register some changed sources.

eric ide

mercurial