482 msg = self.tr("No documentation available.") |
501 msg = self.tr("No documentation available.") |
483 self.__documentationViewer.documentationReady( |
502 self.__documentationViewer.documentationReady( |
484 msg, isDocWarning=True) |
503 msg, isDocWarning=True) |
485 else: |
504 else: |
486 self.__documentationViewer.documentationReady(docu) |
505 self.__documentationViewer.documentationReady(docu) |
|
506 |
|
507 def gotoDefinition(self, editor): |
|
508 """ |
|
509 Public slot to find the definition for the word at the cursor position |
|
510 and go to it. |
|
511 |
|
512 Note: This is executed upon a mouse click sequence. |
|
513 |
|
514 @param editor reference to the calling editor |
|
515 @type QScintilla.Editor.Editor |
|
516 """ |
|
517 if not self.__plugin.getPreferences("MouseClickEnabled"): |
|
518 return |
|
519 |
|
520 idString = self.__idString(editor) |
|
521 if not idString: |
|
522 return |
|
523 |
|
524 filename = editor.getFileName() |
|
525 source = editor.text() |
|
526 line, index = editor.getCursorPosition() |
|
527 offset = len("".join(source.splitlines(True)[:line])) + index |
|
528 |
|
529 self.__ensureActive(idString) |
|
530 self.sendJson("gotoDefinition", { |
|
531 "FileName": filename, |
|
532 "Offset": offset, |
|
533 "Source": editor.text(), |
|
534 "SysPath": sys.path, |
|
535 }, idString=idString) |
|
536 |
|
537 def __gotoDefinitionResult(self, result): |
|
538 """ |
|
539 Private method to handle the "Goto Definition" result sent by |
|
540 the client. |
|
541 |
|
542 @param result dictionary containing the result data |
|
543 @type dict |
|
544 """ |
|
545 if "Error" not in result: |
|
546 # ignore errors silently |
|
547 if "Location" in result: |
|
548 location = result["Location"] |
|
549 try: |
|
550 self.__vm.openSourceFile( |
|
551 location["ModulePath"], location["Line"], addNext=True) |
|
552 except TypeError: |
|
553 # backward compatibility; <= 17.03 |
|
554 self.__vm.openSourceFile( |
|
555 location["ModulePath"], location["Line"], next=True) |
|
556 else: |
|
557 e5App().getObject("UserInterface").statusBar().showMessage( |
|
558 self.tr('Code Assist: No definition found'), 5000) |
487 |
559 |
488 ####################################################################### |
560 ####################################################################### |
489 ## Methods below handle the network connection |
561 ## Methods below handle the network connection |
490 ####################################################################### |
562 ####################################################################### |
491 |
563 |
795 |
867 |
796 ####################################################################### |
868 ####################################################################### |
797 ## Methods below handle setting/unsetting the hook methods |
869 ## Methods below handle setting/unsetting the hook methods |
798 ####################################################################### |
870 ####################################################################### |
799 |
871 |
800 def connectEditor(self, editor): |
872 ## def connectEditor(self, editor): |
801 """ |
873 ## """ |
802 Public method to connect an editor. |
874 ## Public method to connect an editor. |
803 |
875 ## |
804 @param editor reference to the editor |
876 ## @param editor reference to the editor |
805 @type QScintilla.Editor.Editor |
877 ## @type QScintilla.Editor.Editor |
806 """ |
878 ## """ |
807 # TODO: special treatment for project files |
879 ## # TODO: special treatment for project files |
808 if self.isSupportedLanguage(editor.getLanguage()): |
880 ## if self.isSupportedLanguage(editor.getLanguage()): |
809 if self.__plugin.getPreferences("CodeAssistEnabled") and \ |
881 ## if self.__plugin.getPreferences("CodeAssistEnabled") and \ |
810 editor.getCompletionListHook("rope") is None: |
882 ## editor.getCompletionListHook("rope") is None: |
811 self.__setAutoCompletionHook(editor) |
883 ## self.__setAutoCompletionHook(editor) |
812 if self.__plugin.getPreferences("CodeAssistCalltipsEnabled") and \ |
884 ## if self.__plugin.getPreferences("CodeAssistCalltipsEnabled") and \ |
813 editor.getCallTipHook("rope") is None: |
885 ## editor.getCallTipHook("rope") is None: |
814 self.__setCalltipsHook(editor) |
886 ## self.__setCalltipsHook(editor) |
815 else: |
887 ## else: |
816 self.disconnectEditor(editor) |
888 ## self.disconnectEditor(editor) |
817 |
889 ## |
818 def disconnectEditor(self, editor): |
890 ## def disconnectEditor(self, editor): |
819 """ |
891 ## """ |
820 Public method to disconnect an editor. |
892 ## Public method to disconnect an editor. |
821 |
893 ## |
822 @param editor reference to the editor |
894 ## @param editor reference to the editor |
823 @type QScintilla.Editor.Editor |
895 ## @type QScintilla.Editor.Editor |
824 """ |
896 ## """ |
825 if editor.getCompletionListHook("rope"): |
897 ## if editor.getCompletionListHook("rope"): |
826 self.__unsetAutoCompletionHook(editor) |
898 ## self.__unsetAutoCompletionHook(editor) |
827 if editor.getCallTipHook("rope"): |
899 ## if editor.getCallTipHook("rope"): |
828 self.__unsetCalltipsHook(editor) |
900 ## self.__unsetCalltipsHook(editor) |
829 |
901 ## |
830 def __setAutoCompletionHook(self, editor): |
902 ## def __setAutoCompletionHook(self, editor): |
831 """ |
903 ## """ |
832 Private method to set the auto-completion hook. |
904 ## Private method to set the auto-completion hook. |
833 |
905 ## |
834 @param editor reference to the editor |
906 ## @param editor reference to the editor |
835 @type QScintilla.Editor.Editor |
907 ## @type QScintilla.Editor.Editor |
836 """ |
908 ## """ |
837 try: |
909 ## try: |
838 editor.addCompletionListHook("rope", self.requestCompletions, True) |
910 ## editor.addCompletionListHook("rope", self.requestCompletions, True) |
839 self.__asyncCompletions = True |
911 ## self.__asyncCompletions = True |
840 except TypeError: |
912 ## except TypeError: |
841 # backward compatibility for eric6 before 17.11 |
913 ## # backward compatibility for eric6 before 17.11 |
842 editor.addCompletionListHook("rope", self.getCompletions) |
914 ## editor.addCompletionListHook("rope", self.getCompletions) |
843 self.__asyncCompletions = False |
915 ## self.__asyncCompletions = False |
844 |
916 ## |
845 def __unsetAutoCompletionHook(self, editor): |
917 ## def __unsetAutoCompletionHook(self, editor): |
846 """ |
918 ## """ |
847 Private method to unset the auto-completion hook. |
919 ## Private method to unset the auto-completion hook. |
848 |
920 ## |
849 @param editor reference to the editor |
921 ## @param editor reference to the editor |
850 @type QScintilla.Editor.Editor |
922 ## @type QScintilla.Editor.Editor |
851 """ |
923 ## """ |
852 editor.removeCompletionListHook("rope") |
924 ## editor.removeCompletionListHook("rope") |
853 |
925 ## |
854 def __setCalltipsHook(self, editor): |
926 ## def __setCalltipsHook(self, editor): |
855 """ |
927 ## """ |
856 Private method to set the calltip hook. |
928 ## Private method to set the calltip hook. |
857 |
929 ## |
858 @param editor reference to the editor |
930 ## @param editor reference to the editor |
859 @type QScintilla.Editor.Editor |
931 ## @type QScintilla.Editor.Editor |
860 """ |
932 ## """ |
861 editor.addCallTipHook("rope", self.getCallTips) |
933 ## editor.addCallTipHook("rope", self.getCallTips) |
862 |
934 ## |
863 def __unsetCalltipsHook(self, editor): |
935 ## def __unsetCalltipsHook(self, editor): |
864 """ |
936 ## """ |
865 Private method to unset the calltip hook. |
937 ## Private method to unset the calltip hook. |
866 |
938 ## |
867 @param editor reference to the editor |
939 ## @param editor reference to the editor |
868 @type QScintilla.Editor.Editor |
940 ## @type QScintilla.Editor.Editor |
869 """ |
941 ## """ |
870 editor.removeCallTipHook("rope") |
942 ## editor.removeCallTipHook("rope") |