--- a/RefactoringRope/RefactoringClient.py Mon Sep 18 20:05:28 2017 +0200 +++ b/RefactoringRope/RefactoringClient.py Tue Sep 19 18:59:14 2017 +0200 @@ -452,7 +452,7 @@ self.__progressHandle = ProgressHandle(self, params["Title"], False) try: changes = self.__changes[params["ChangeGroup"]] - self.___project.do(changes, self.__progressHandle) + self.__project.do(changes, self.__progressHandle) except Exception as err: errorDict = self.__handleRopeError(err) self.__progressHandle.reset() @@ -461,6 +461,7 @@ result = { "Subcommand": "ChangesApplied", "ChangeGroup": params["ChangeGroup"], + "Title": params["Title"], "ChangedFiles": [ res.real_path for res in changes.get_changed_resources() ], @@ -477,21 +478,27 @@ the server @type dict """ - changes = self.__changes[params["ChangeGroup"]] + try: + changes = self.__changes[params["ChangeGroup"]] + description = changes.description + except KeyError: + changes = None + description = "" changesData = [] - for change in changes: - changeTitle = str(change) - try: - changeText = change.get_description() - except AttributeError: - changeText = None - changesData.append([changeTitle, changeText]) + if changes is not None: + for change in changes.changes: + changeTitle = str(change) + try: + changeText = change.get_description() + except AttributeError: + changeText = None + changesData.append([changeTitle, changeText]) result = { "Subcommand": "PreviewChanges", "ChangeGroup": params["ChangeGroup"], - "Description": changes.description, + "Description": description, "Changes": changesData, } @@ -506,6 +513,7 @@ the server @type dict """ + changeGroup = params["ChangeGroup"] title = params["Title"] filename = params["FileName"] offset = params["Offset"] @@ -517,7 +525,8 @@ errorDict = {} changes = [] result = { - "ChangeGroup": params["ChangeGroup"], + "ChangeGroup": changeGroup, + "Title": title, } import rope.refactor.rename @@ -545,7 +554,7 @@ newName, resources=resources, in_hierarchy=renameHierarchy, - unsure=self.__confirmUnsure, + unsure=lambda o: self.__confirmUnsure(o, changeGroup), docs=renameInStrings, task_handle=self.__progressHandle) except Exception as err: @@ -553,24 +562,38 @@ self.__progressHandle.reset() self.__progressHandle = None - if changes: - self.__changes[params["ChangeGroup"]] = changes + self.__changes[changeGroup] = changes result["Subcommand"] = "ChangesCalculated" result.update(errorDict) self.sendJson("Changes", result) - def __confirmUnsure(self, occurrence): + def __confirmUnsure(self, occurrence, changeGroup): """ Private method to confirm unsure occurrences. @parameter occurrence reference to the occurrence object @type rope.refactor.occurrences.Occurrence + @param changeGroup name of the change group + @type str @return flag indicating an occurrence @rtype bool """ - # TODO: implement this method; synchronous poll + filename = occurrence.resource.real_path + start, end = occurrence.get_primary_range() + + self.sendJson("Changes", { + "Subcommand": "ConfirmUnsure", + "ChangeGroup": changeGroup, + "FileName": filename, + "StartOffset": start, + "EndOffset": end, + }) + + answer = self.poll(waitMethod="ConfirmUnsure") + + return answer["Answer"] if __name__ == '__main__': if len(sys.argv) != 4: