eric7/JediInterface/JediServer.py

branch
eric7
changeset 8668
d29c775b8bd7
parent 8666
3a62b4009df9
child 8669
c26ecdb00a8b
equal deleted inserted replaced
8667:99dfcefcc4d8 8668:d29c775b8bd7
88 "DocumentationResult": self.__processDocumentationResult, 88 "DocumentationResult": self.__processDocumentationResult,
89 "HoverHelpResult": self.__processHoverHelpResult, 89 "HoverHelpResult": self.__processHoverHelpResult,
90 "GotoDefinitionResult": self.__processGotoDefinitionResult, 90 "GotoDefinitionResult": self.__processGotoDefinitionResult,
91 "GotoReferencesResult": self.__processGotoReferencesResult, 91 "GotoReferencesResult": self.__processGotoReferencesResult,
92 92
93 "RenameVariableDiff": self.__showRenameVariableDiff, 93 "RefactoringDiff": self.__showRefactoringDiff,
94 "RefactoringApplyResult": self.__checkRefactoringResult, 94 "RefactoringApplyResult": self.__checkRefactoringResult,
95 95
96 "ClientException": self.__processClientException, 96 "ClientException": self.__processClientException,
97 } 97 }
98 98
509 ) 509 )
510 510
511 if ok and newName: 511 if ok and newName:
512 filename = editor.getFileName() 512 filename = editor.getFileName()
513 line, index = editor.getCursorPosition() 513 line, index = editor.getCursorPosition()
514 line += 1 # jedi line numbers are 1 based
515 source = editor.text() 514 source = editor.text()
516 515
517 self.__ensureActive(idString) 516 self.__ensureActive(idString)
518 517
519 euuid = str(uuid.uuid4()) 518 euuid = str(uuid.uuid4())
520 self.__editors[euuid] = editor 519 self.__editors[euuid] = editor
521 520
522 self.sendJson("renameVariable", { 521 self.sendJson("renameVariable", {
523 "FileName": filename, 522 "FileName": filename,
524 "Source": source, 523 "Source": source,
525 "Line": line, 524 "Line": line + 1,
526 "Index": index, 525 "Index": index,
527 "Uuid": euuid, 526 "Uuid": euuid,
528 "NewName": newName, 527 "NewName": newName,
529 }, idString=idString) 528 }, idString=idString)
530 529
531 def __showRenameVariableDiff(self, result): 530 @pyqtSlot()
532 """ 531 def refactoringExtractNewVariable(self):
533 Private method to show the diff of the Rename Variable refactoring. 532 """
533 Public slot to extract a statement to a new variable.
534 """
535 editor = self.__vm.activeWindow()
536 if editor:
537 idString = self.__idString(editor)
538 if not idString:
539 return
540
541 newName, ok = QInputDialog.getText(
542 None,
543 self.tr("Extract Variable"),
544 self.tr("Enter the name for the new variable:"),
545 QLineEdit.EchoMode.Normal
546 )
547
548 if ok and newName:
549 filename = editor.getFileName()
550 sLine, sIndex, eLine, eIndex = editor.getSelection()
551 source = editor.text()
552
553 self.__ensureActive(idString)
554
555 euuid = str(uuid.uuid4())
556 self.__editors[euuid] = editor
557
558 self.sendJson("extractVariable", {
559 "FileName": filename,
560 "Source": source,
561 "Line": sLine + 1,
562 "Index": sIndex,
563 "EndLine": eLine + 1,
564 "EndIndex": eIndex,
565 "Uuid": euuid,
566 "NewName": newName,
567 }, idString=idString)
568
569 @pyqtSlot()
570 def refactoringInlineVariable(self):
571 """
572 Public slot to inline the selected variable.
573
574 Note: This is the opposite to Extract New Variable.
575 """
576 editor = self.__vm.activeWindow()
577 if editor:
578 idString = self.__idString(editor)
579 if not idString:
580 return
581
582 filename = editor.getFileName()
583 line, index = editor.getCursorPosition()
584 source = editor.text()
585
586 self.__ensureActive(idString)
587
588 euuid = str(uuid.uuid4())
589 self.__editors[euuid] = editor
590
591 self.sendJson("inlineVariable", {
592 "FileName": filename,
593 "Source": source,
594 "Line": line + 1,
595 "Index": index,
596 "Uuid": euuid,
597 }, idString=idString)
598
599 def __showRefactoringDiff(self, result):
600 """
601 Private method to show the diff of a refactoring.
534 602
535 @param result dictionary containing the result data 603 @param result dictionary containing the result data
536 @type dict 604 @type dict
537 """ 605 """
538 if "Error" not in result: 606 if "Error" not in result:
539 # ignore errors silently
540 euuid = result["Uuid"] 607 euuid = result["Uuid"]
541 diff = result["Diff"] 608 diff = result["Diff"]
542 dlg = RefactoringPreviewDialog(self.tr("Rename Variable"), diff) 609 dlg = RefactoringPreviewDialog(self.tr("Rename Variable"), diff)
543 if dlg.exec() == QDialog.DialogCode.Accepted: 610 if dlg.exec() == QDialog.DialogCode.Accepted:
544 self.__applyRefactoring(euuid) 611 self.__applyRefactoring(euuid)
545 else: 612 else:
546 self.__cancelRefactoring(euuid) 613 self.__cancelRefactoring(euuid)
614 else:
615 EricMessageBox.critical(
616 None,
617 self.tr("Refactoring"),
618 self.tr("<p>The refactoring could not be performed.</p>"
619 "<p>Reason: {0}</p>").format(result["ErrorString"])
620 )
547 621
548 def __applyRefactoring(self, uid): 622 def __applyRefactoring(self, uid):
549 """ 623 """
550 Private method to apply a given refactoring. 624 Private method to apply a given refactoring.
551 625
586 @param result dictionary containing the result data 660 @param result dictionary containing the result data
587 @type dict 661 @type dict
588 """ 662 """
589 if "Error" in result: 663 if "Error" in result:
590 EricMessageBox.critical( 664 EricMessageBox.critical(
591 self, 665 None,
592 self.tr("Apply Refactoring"), 666 self.tr("Apply Refactoring"),
593 self.tr("<p>The refactoring could not be applied.</p>" 667 self.tr("<p>The refactoring could not be applied.</p>"
594 "<p>Reason: {0}</p>").format(result["ErrorString"]) 668 "<p>Reason: {0}</p>").format(result["ErrorString"])
595 ) 669 )
596 670

eric ide

mercurial