--- a/RefactoringRope/RefactoringClient.py Thu Sep 14 19:39:11 2017 +0200 +++ b/RefactoringRope/RefactoringClient.py Fri Sep 15 19:50:07 2017 +0200 @@ -17,9 +17,11 @@ path = os.path.join(os.path.dirname(__file__), 'rope_py3') else: path = os.path.join(os.path.dirname(__file__), 'rope_py2') + str = unicode # __IGNORE_WARNING__ sys.path.insert(0, path) import rope.base.project +import rope.base.libutils from JsonClient import JsonClient @@ -68,8 +70,75 @@ not self.__progressHandle.is_stopped(): self.__progressHandle.stop() + elif method == "Validate": + self.__project.validate(self.__project.root) + + elif method == "QueryReferences": + self.__queryReferences(params) + elif method == "ping": self.sendJson("pong", {}) + + def __handleRopeError(self, err): + """ + Private method to process a rope error. + + @param err rope exception object + @type Exception + @return dictionary containing the error information + @rtype dict + """ + ropeError = str(type(err)).split()[-1] + ropeError = ropeError[1:-2].split('.')[-1] + errorDict = { + "Error": ropeError, + "ErrorString": str(err), + } + if ropeError == 'ModuleSyntaxError': + errorDict["ErrorFile"] = err.filename + errorDict["ErrorLine"] = err.lineno + + return errorDict + + def __queryReferences(self, params): + """ + Private method to handle the Find References action. + + @param params dictionary containing the method parameters sent by + the server + @type dict + """ + title = params["Title"] + filename = params["FileName"] + offset = params["Offset"] + + errorDict = {} + occurrences = [] + + import rope.contrib.findit + from ProgressHandle import ProgressHandle + resource = rope.base.libutils.path_to_resource( + self.__project, filename) + handle = ProgressHandle(self, title, True) + try: + occurrences = rope.contrib.findit.find_occurrences( + self.__project, resource, offset, + unsure=True, in_hierarchy=True, task_handle=handle) + except Exception as err: + errorDict = self.__handleRopeError(err) + handle.reset() + + result = { + "Title": title, + "EntriesCount": len(occurrences), + "Entries": [ + [occurrence.resource.real_path, occurrence.lineno, + occurrence.unsure] for occurrence in occurrences + ], + } + result.update(errorDict) + + self.sendJson("QueryReferencesResult", result) if __name__ == '__main__': if len(sys.argv) != 4: