72 "CalculateUseFunctionChanges": self.__calculateUseFunctionChanges, |
72 "CalculateUseFunctionChanges": self.__calculateUseFunctionChanges, |
73 "CalculateIntroduceFactoryChanges": |
73 "CalculateIntroduceFactoryChanges": |
74 self.__calculateIntroduceFactoryChanges, |
74 self.__calculateIntroduceFactoryChanges, |
75 "CalculateIntroduceParameterChanges": |
75 "CalculateIntroduceParameterChanges": |
76 self.__calculateIntroduceParameterChanges, |
76 self.__calculateIntroduceParameterChanges, |
|
77 "CalculateImportsChanges": self.__calculateImportsChanges, |
77 } |
78 } |
78 |
79 |
79 from FileSystemCommands import RefactoringClientFileSystemCommands |
80 from FileSystemCommands import RefactoringClientFileSystemCommands |
80 self.__fsCommands = RefactoringClientFileSystemCommands(self) |
81 self.__fsCommands = RefactoringClientFileSystemCommands(self) |
81 |
82 |
1040 |
1041 |
1041 result["Subcommand"] = "ChangesCalculated" |
1042 result["Subcommand"] = "ChangesCalculated" |
1042 result.update(errorDict) |
1043 result.update(errorDict) |
1043 |
1044 |
1044 self.sendJson("Changes", result) |
1045 self.sendJson("Changes", result) |
|
1046 |
|
1047 def __calculateImportsChanges(self, params): |
|
1048 """ |
|
1049 Private method to calculate the 'Import' changes based on the |
|
1050 parameters sent by the server. |
|
1051 |
|
1052 @param params dictionary containing the method parameters sent by |
|
1053 the server |
|
1054 @type dict |
|
1055 """ |
|
1056 changeGroup = params["ChangeGroup"] |
|
1057 title = params["Title"] |
|
1058 filename = params["FileName"] |
|
1059 offset = params["Offset"] |
|
1060 methodName = params["MethodName"] |
|
1061 |
|
1062 errorDict = {} |
|
1063 changes = [] |
|
1064 result = { |
|
1065 "ChangeGroup": changeGroup, |
|
1066 "Title": title, |
|
1067 } |
|
1068 |
|
1069 from rope.refactor.importutils import ImportOrganizer |
|
1070 method = { |
|
1071 "organize_imports": ImportOrganizer.organize_imports, |
|
1072 "expand_star_imports": ImportOrganizer.expand_star_imports, |
|
1073 "relatives_to_absolutes": ImportOrganizer.relatives_to_absolutes, |
|
1074 "froms_to_imports": ImportOrganizer.froms_to_imports, |
|
1075 "handle_long_imports": ImportOrganizer.handle_long_imports, |
|
1076 }[methodName] |
|
1077 importOrganizer = ImportOrganizer(self.__project) |
|
1078 resource = rope.base.libutils.path_to_resource( |
|
1079 self.__project, filename) |
|
1080 try: |
|
1081 changes = method(importOrganizer, resource, offset=offset) |
|
1082 except Exception as err: |
|
1083 errorDict = self.__handleRopeError(err) |
|
1084 |
|
1085 self.__changes[changeGroup] = changes |
|
1086 |
|
1087 # send the change description first |
|
1088 if changes: |
|
1089 description = changes.description |
|
1090 else: |
|
1091 description = "" |
|
1092 self.sendJson("Changes", { |
|
1093 "ChangeGroup": changeGroup, |
|
1094 "Title": title, |
|
1095 "Subcommand": "ChangeDescription", |
|
1096 "Description": description, |
|
1097 }) |
|
1098 |
|
1099 result["Subcommand"] = "ChangesCalculated" |
|
1100 result.update(errorDict) |
|
1101 |
|
1102 self.sendJson("Changes", result) |
1045 |
1103 |
1046 |
1104 |
1047 if __name__ == '__main__': |
1105 if __name__ == '__main__': |
1048 if len(sys.argv) != 4: |
1106 if len(sys.argv) != 4: |
1049 print('Host, port and project path parameters are missing. Abort.') |
1107 print('Host, port and project path parameters are missing. Abort.') |