Editor: added support for 'goto reference' via the mouse click handler. eric7

Wed, 28 Jul 2021 19:46:57 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 28 Jul 2021 19:46:57 +0200
branch
eric7
changeset 8488
b9168b90f830
parent 8487
153b7c3da034
child 8489
45af30c5561d

Editor: added support for 'goto reference' via the mouse click handler.

eric7/QScintilla/Editor.py file | annotate | diff | comparison | revisions
--- a/eric7/QScintilla/Editor.py	Wed Jul 28 17:30:35 2021 +0200
+++ b/eric7/QScintilla/Editor.py	Wed Jul 28 19:46:57 2021 +0200
@@ -7,10 +7,11 @@
 Module implementing the editor component of the eric IDE.
 """
 
+import collections
+import contextlib
+import difflib
 import os
 import re
-import difflib
-import contextlib
 
 import editorconfig
 
@@ -43,6 +44,10 @@
 
 EditorAutoCompletionListID = 1
 TemplateCompletionListID = 2
+ReferencesListID = 3
+
+ReferenceItem = collections.namedtuple(
+    "ReferenceItem", ["modulePath", "codeLine", "line", "column"])
 
 
 class Editor(QsciScintillaCompat):
@@ -5177,6 +5182,7 @@
         @param listId the ID of the user list (should be 1 or 2) (integer)
         @param txt the selected text (string)
         """
+        # custom completions via plug-ins
         if listId == EditorAutoCompletionListID:
             lst = txt.split()
             if len(lst) > 1:
@@ -5203,8 +5209,19 @@
             self.insert(txt)
             self.endUndoAction()
             self.setCursorPosition(line, col + len(txt))
+        
+        # template completions
         elif listId == TemplateCompletionListID:
             self.__applyTemplate(txt, self.getLanguage())
+        
+        # 'goto reference' completions
+        elif listId == ReferencesListID:
+            with contextlib.suppress(ValueError, IndexError):
+                index = self.__referencesList.index(txt)
+                filename, line, column = self.__referencesPositionsList(index)
+                self.__vm.openSourceFile(
+                    filename, lineno=line, pos=column, addNext=True)
+                
     
     def canProvideDynamicAutoCompletion(self):
         """
@@ -8528,6 +8545,31 @@
         for key in keys:
             del self.__mouseClickHandlers[key]
     
+    def gotoReferenceHandler(self, referencesList):
+        """
+        Public method to handle a list of references to perform a goto.
+        
+        @param referencesList list of references for a 'goto' action
+        @type ReferenceItem
+        """
+        referencesList = []
+        referencesPositionsList = []
+        
+        for reference in referencesPositionsList:
+            if (
+                reference.modulePath != self.fileName() and
+                self.getCursorPosition()[0] + 1 != reference.line
+            ):
+                referencesList.append(
+                    "{0}\t{1}".format(reference.line, reference.codeLine))
+                referencesPositionsList.append(
+                    reference.modulePath, reference.line, reference.column)
+        
+        if referencesList:
+            self.__referencesList = referencesList
+            self.__referencesPositionsList = referencesPositionsList
+            self.showUserList(ReferencesListID, referencesList)
+    
     #######################################################################
     ## Methods implementing a Shell interface
     #######################################################################

eric ide

mercurial