--- a/eric7/JediInterface/JediServer.py Tue Oct 05 18:13:40 2021 +0200 +++ b/eric7/JediInterface/JediServer.py Tue Oct 05 19:36:02 2021 +0200 @@ -596,6 +596,45 @@ "Uuid": euuid, }, idString=idString) + @pyqtSlot() + def refactoringExtractFunction(self): + """ + Public slot to extract an expression to a function. + """ + editor = self.__vm.activeWindow() + if editor: + idString = self.__idString(editor) + if not idString: + return + + newName, ok = QInputDialog.getText( + None, + self.tr("Extract Function"), + self.tr("Enter the name for the function:"), + QLineEdit.EchoMode.Normal + ) + + if ok and newName: + filename = editor.getFileName() + sLine, sIndex, eLine, eIndex = editor.getSelection() + source = editor.text() + + self.__ensureActive(idString) + + euuid = str(uuid.uuid4()) + self.__editors[euuid] = editor + + self.sendJson("extractFunction", { + "FileName": filename, + "Source": source, + "Line": sLine + 1, + "Index": sIndex, + "EndLine": eLine + 1, + "EndIndex": eIndex, + "Uuid": euuid, + "NewName": newName, + }, idString=idString) + def __showRefactoringDiff(self, result): """ Private method to show the diff of a refactoring.