RefactoringRope/CodeAssistClient.py

changeset 293
dd1c7ed6d880
parent 291
da88cb84ae30
child 302
2e853e2f2430
equal deleted inserted replaced
292:3ead66c44f3f 293:dd1c7ed6d880
28 28
29 class CodeAssistClient(JsonClient): 29 class CodeAssistClient(JsonClient):
30 """ 30 """
31 Class implementing the code assist client interface to rope. 31 Class implementing the code assist client interface to rope.
32 """ 32 """
33 IdProject = "Project"
34
33 def __init__(self, host, port, idString, projectPath): 35 def __init__(self, host, port, idString, projectPath):
34 """ 36 """
35 Constructor 37 Constructor
36 38
37 @param host ip address the background service is listening 39 @param host ip address the background service is listening
51 "configChanged": self.__configChanged, 53 "configChanged": self.__configChanged,
52 "closeProject": self.__closeProject, 54 "closeProject": self.__closeProject,
53 "getCompletions": self.__getCompletions, 55 "getCompletions": self.__getCompletions,
54 "getCallTips": self.__getCallTips, 56 "getCallTips": self.__getCallTips,
55 "getDocumentation": self.__getDocumentation, 57 "getDocumentation": self.__getDocumentation,
58 "gotoDefinition": self.__gotoDefinition,
56 "reportChanged": self.__reportChanged, 59 "reportChanged": self.__reportChanged,
57 } 60 }
58 61
59 self.__projectpath = projectPath 62 self.__projectpath = projectPath
60 self.__project = rope.base.project.Project(self.__projectpath) 63 self.__project = rope.base.project.Project(self.__projectpath)
226 filename = params["FileName"] 229 filename = params["FileName"]
227 source = params["Source"] 230 source = params["Source"]
228 offset = params["Offset"] 231 offset = params["Offset"]
229 maxfixes = params["MaxFixes"] 232 maxfixes = params["MaxFixes"]
230 233
231 self.__project.prefs.set("python_path", params["SysPath"]) 234 if not self.__id == CodeAssistClient.IdProject:
235 self.__project.prefs.set("python_path", params["SysPath"])
232 if filename: 236 if filename:
233 resource = rope.base.libutils.path_to_resource( 237 resource = rope.base.libutils.path_to_resource(
234 self.__project, filename) 238 self.__project, filename)
235 else: 239 else:
236 resource = None 240 resource = None
372 typ = "" 376 typ = ""
373 name = "" 377 name = ""
374 378
375 return typ, name 379 return typ, name
376 380
381 def __gotoDefinition(self, params):
382 """
383 Private method to handle the Goto Definition action.
384
385 @param params dictionary containing the method parameters sent by
386 the server
387 @type dict
388 """
389 import rope.base.libutils
390
391 filename = params["FileName"]
392 offset = params["Offset"]
393 source = params["Source"]
394
395 self.__project.prefs.set("python_path", params["SysPath"])
396 if filename:
397 resource = rope.base.libutils.path_to_resource(
398 self.__project, filename)
399 else:
400 resource = None
401
402 errorDict = {}
403 result = {}
404
405 import rope.contrib.findit
406 try:
407 location = rope.contrib.findit.find_definition(
408 self.__project, source, offset, resource)
409 except Exception as err:
410 errorDict = self.__handleRopeError(err)
411
412 if location is not None:
413 result["Location"] = {
414 "ModulePath": location.resource.real_path,
415 "Line": location.lineno,
416 }
417 result.update(errorDict)
418
419 self.sendJson("GotoDefinitionResult", result)
420
377 def __reportChanged(self, params): 421 def __reportChanged(self, params):
378 """ 422 """
379 Private method to register some changed sources. 423 Private method to register some changed sources.
380 424
381 @param params dictionary containing the method parameters sent by 425 @param params dictionary containing the method parameters sent by

eric ide

mercurial