--- a/RefactoringRope/RefactoringClient.py Sat Sep 23 14:17:49 2017 +0200 +++ b/RefactoringRope/RefactoringClient.py Sat Sep 23 15:20:09 2017 +0200 @@ -75,6 +75,7 @@ "CalculateIntroduceParameterChanges": self.__calculateIntroduceParameterChanges, "CalculateImportsChanges": self.__calculateImportsChanges, + "CalculateRestructureChanges": self.__calculateRestructureChanges, } from FileSystemCommands import RefactoringClientFileSystemCommands @@ -1100,6 +1101,49 @@ result.update(errorDict) self.sendJson("Changes", result) + + def __calculateRestructureChanges(self, params): + """ + Private method to calculate the 'Restructure' changes based on the + parameters sent by the server. + + @param params dictionary containing the method parameters sent by + the server + @type dict + """ + changeGroup = params["ChangeGroup"] + title = params["Title"] + pattern = params["Pattern"] + goal = params["Goal"] + args = params["Args"] + imports = params["Imports"] + + errorDict = {} + changes = [] + result = { + "ChangeGroup": changeGroup, + "Title": title, + } + + import rope.refactor.restructure + self.__project.validate(self.__project.root) + self.__progressHandle = ProgressHandle(self, title, True) + try: + restructuring = rope.refactor.restructure.Restructure( + self.__project, pattern, goal, args=args, imports=imports) + changes = restructuring.get_changes( + task_handle=self.__progressHandle) + except Exception as err: + errorDict = self.__handleRopeError(err) + self.__progressHandle.reset() + self.__progressHandle = None + + self.__changes[changeGroup] = changes + + result["Subcommand"] = "ChangesCalculated" + result.update(errorDict) + + self.sendJson("Changes", result) if __name__ == '__main__':