RefactoringRope/CodeAssistClient.py

branch
eric7
changeset 370
9d246420f284
parent 365
f740b50380df
child 374
958f34e97952
equal deleted inserted replaced
369:ae43998a0cf8 370:9d246420f284
52 "closeProject": self.__closeProject, 52 "closeProject": self.__closeProject,
53 "getCompletions": self.__getCompletions, 53 "getCompletions": self.__getCompletions,
54 "getCallTips": self.__getCallTips, 54 "getCallTips": self.__getCallTips,
55 "getDocumentation": self.__getDocumentation, 55 "getDocumentation": self.__getDocumentation,
56 "gotoDefinition": self.__gotoDefinition, 56 "gotoDefinition": self.__gotoDefinition,
57 "gotoReferences": self.__getReferences,
57 "reportChanged": self.__reportChanged, 58 "reportChanged": self.__reportChanged,
58 } 59 }
59 60
60 from FileSystemCommands import RefactoringClientFileSystemCommands 61 from FileSystemCommands import RefactoringClientFileSystemCommands
61 self.__fsCommands = RefactoringClientFileSystemCommands(self) 62 self.__fsCommands = RefactoringClientFileSystemCommands(self)
395 import rope.base.libutils 396 import rope.base.libutils
396 397
397 filename = params["FileName"] 398 filename = params["FileName"]
398 offset = params["Offset"] 399 offset = params["Offset"]
399 source = params["Source"] 400 source = params["Source"]
401 uid = params["Uuid"]
400 402
401 self.__project.prefs.set("python_path", params["SysPath"]) 403 self.__project.prefs.set("python_path", params["SysPath"])
402 resource = ( 404 resource = (
403 rope.base.libutils.path_to_resource(self.__project, filename) 405 rope.base.libutils.path_to_resource(self.__project, filename)
404 if filename else 406 if filename else
419 if location is not None: 421 if location is not None:
420 result["Location"] = { 422 result["Location"] = {
421 "ModulePath": location.resource.real_path, 423 "ModulePath": location.resource.real_path,
422 "Line": location.lineno, 424 "Line": location.lineno,
423 } 425 }
426 result["Uuid"] = uid
424 result.update(errorDict) 427 result.update(errorDict)
425 428
426 self.sendJson("GotoDefinitionResult", result) 429 self.sendJson("GotoDefinitionResult", result)
430
431 def __getReferences(self, params):
432 """
433 Private method to get the places a parameter is referenced.
434
435 @param params dictionary containing the method parameters sent by
436 the server
437 @type dict
438 """
439 import rope.base.libutils
440
441 filename = params["FileName"]
442 offset = params["Offset"]
443 line = params["Line"]
444 uid = params["Uuid"]
445
446 self.__project.prefs.set("python_path", params["SysPath"])
447 resource = (
448 rope.base.libutils.path_to_resource(self.__project, filename)
449 if filename else
450 None
451 )
452
453 errorDict = {}
454 gotoReferences = []
455
456 import rope.contrib.findit
457 try:
458 occurrences = rope.contrib.findit.find_occurrences(
459 self.__project, resource, offset, in_hierarchy=True)
460 for occurrence in occurrences:
461 if (
462 occurrence.lineno == line and
463 occurrence.resource.real_path == filename
464 ):
465 continue
466 gotoReferences.append({
467 'ModulePath': occurrence.resource.real_path,
468 'Line': occurrence.lineno,
469 'Code': occurrence.resource.read().splitlines()[
470 occurrence.lineno - 1],
471 })
472 except Exception as err:
473 errorDict = self.__handleRopeError(err)
474
475 result = {
476 "GotoReferencesList": gotoReferences,
477 "Uuid": uid,
478 }
479 result.update(errorDict)
480
481 self.sendJson("GotoReferencesResult", result)
427 482
428 def __reportChanged(self, params): 483 def __reportChanged(self, params):
429 """ 484 """
430 Private method to register some changed sources. 485 Private method to register some changed sources.
431 486

eric ide

mercurial