--- a/RefactoringRope/RefactoringClient.py Fri Sep 22 19:47:09 2017 +0200 +++ b/RefactoringRope/RefactoringClient.py Fri Sep 22 19:47:36 2017 +0200 @@ -65,6 +65,8 @@ "CalculateExtractChanges": self.__calculateExtractChanges, "RequestInlineType": self.__requestInlineType, "CalculateInlineChanges": self.__calculateInlineChanges, + "RequestMoveType": self.__requestMoveType, + "CalculateMoveChanges": self.__calculateMoveChanges, } from FileSystemCommands import RefactoringClientFileSystemCommands @@ -726,7 +728,7 @@ def __calculateInlineChanges(self, params): """ - Private method to calculate the 'Extract' changes based on the + Private method to calculate the 'Inline' changes based on the parameters sent by the server. @param params dictionary containing the method parameters sent by @@ -776,6 +778,110 @@ result.update(errorDict) self.sendJson("Changes", result) + + def __requestMoveType(self, params): + """ + Private method to determine the 'Move Method' changes type 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"] + filename = params["FileName"] + offset = params["Offset"] + + errorDict = {} + result = { + "Subcommand": "MoveType", + "ChangeGroup": changeGroup, + "Title": title, + } + + import rope.refactor.move + resource = rope.base.libutils.path_to_resource( + self.__project, filename) + try: + mover = rope.refactor.move.create_move( + self.__project, resource, offset) + if isinstance(mover, rope.refactor.move.MoveGlobal): + result.update({ + "Kind": "move_global_method", + "Method": "", + }) + else: + result.update({ + "Kind": "move_method", + "Method": mover.get_method_name(), + }) + except Exception as err: + errorDict = self.__handleRopeError(err) + + result.update(errorDict) + + self.sendJson("Changes", result) + + def __calculateMoveChanges(self, params): + """ + Private method to calculate the 'Move ...' 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"] + filename = params["FileName"] + offset = params["Offset"] + kind = params["Kind"] + newName = params["NewName"] + attribute = params["Attribute"] + destination = params["DestinationModule"] + + errorDict = {} + changes = [] + result = { + "ChangeGroup": changeGroup, + "Title": title, + } + + import rope.refactor.move + resource = rope.base.libutils.path_to_resource( + self.__project, filename) + from ProgressHandle import ProgressHandle + self.__progressHandle = ProgressHandle(self, title, True) + try: + mover = rope.refactor.move.create_move( + self.__project, resource, offset) + if kind == "move_method": + changes = mover.get_changes( + attribute, newName, task_handle=self.__progressHandle) + else: + if kind == "move_global_method": + dest = self.__project.get_pycore().find_module( + os.path.splitext(destination)[0]) + else: + # move_module + if destination.endswith(os.sep): + destination = destination[:-1] + dest = self.__project.get_pycore().find_module( + destination) + changes = mover.get_changes( + dest, 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__': if len(sys.argv) != 4: