diff options
| -rw-r--r-- | pyGHDL/lsp/document.py | 2 | ||||
| -rw-r--r-- | pyGHDL/lsp/vhdl_ls.py | 5 | ||||
| -rw-r--r-- | pyGHDL/lsp/workspace.py | 25 | 
3 files changed, 25 insertions, 7 deletions
| diff --git a/pyGHDL/lsp/document.py b/pyGHDL/lsp/document.py index 1a6a20f39..eec5c5bee 100644 --- a/pyGHDL/lsp/document.py +++ b/pyGHDL/lsp/document.py @@ -197,7 +197,7 @@ class Document(object):          pos = files_map.File_Line_To_Position(self._fe, position["line"] + 1)          return files_map.File_Pos_To_Location(self._fe, pos) + position["character"] -    def goto_definition(self, position): +    def find_definition(self, position):          loc = self.position_to_location(position)          return references.find_definition_by_loc(self._tree, loc) diff --git a/pyGHDL/lsp/vhdl_ls.py b/pyGHDL/lsp/vhdl_ls.py index 9d5b71f59..bd6abcf41 100644 --- a/pyGHDL/lsp/vhdl_ls.py +++ b/pyGHDL/lsp/vhdl_ls.py @@ -24,6 +24,7 @@ class VhdlLanguageServer(object):              "textDocument/didSave": self.textDocument_didSave,              "textDocument/hover": self.textDocument_hover,              "textDocument/definition": self.textDocument_definition, +            "textDocument/implementation": self.textDocument_implementation,              "textDocument/documentSymbol": self.textDocument_documentSymbol,              # 'textDocument/completion': self.completion,              "textDocument/rangeFormatting": self.textDocument_rangeFormatting, @@ -60,6 +61,7 @@ class VhdlLanguageServer(object):              #                'triggerCharacters': ['(', ',']              #            },              "definitionProvider": True, +            "implementationProvider": True,              "referencesProvider": False,              "documentHighlightProvider": False,              "documentSymbolProvider": True, @@ -116,6 +118,9 @@ class VhdlLanguageServer(object):      def textDocument_definition(self, textDocument=None, position=None):          return self.workspace.goto_definition(textDocument["uri"], position) +    def textDocument_implementation(self, textDocument=None, position=None): +        return self.workspace.goto_implementation(textDocument["uri"], position) +      def textDocument_documentSymbol(self, textDocument=None):          doc = self.workspace.get_or_create_document(textDocument["uri"])          return doc.document_symbols() diff --git a/pyGHDL/lsp/workspace.py b/pyGHDL/lsp/workspace.py index fe808c23c..6c312b203 100644 --- a/pyGHDL/lsp/workspace.py +++ b/pyGHDL/lsp/workspace.py @@ -388,19 +388,32 @@ class Workspace(object):          return res      def goto_definition(self, doc_uri, position): -        decl = self._docs[doc_uri].goto_definition(position) +        decl = self._docs[doc_uri].find_definition(position)          if decl is None:              return None          decl_loc = self.declaration_to_location(decl)          if decl_loc is None:              return None -        res = [decl_loc] -        # If the declaration is a component, also add the entity. -        if nodes.Get_Kind(decl) == nodes.Iir_Kind.Component_Declaration: +        return [decl_loc] + +    def goto_implementation(self, doc_uri, position): +        decl = self._docs[doc_uri].find_definition(position) +        if decl is None: +            return None +        k = nodes.Get_Kind(decl) +        if k == nodes.Iir_Kind.Component_Declaration:              ent = libraries.Find_Entity_For_Component(nodes.Get_Identifier(decl))              if ent != nodes.Null_Iir: -                res.append(self.declaration_to_location(nodes.Get_Library_Unit(ent))) -        return res +                decl = nodes.Get_Library_Unit(ent) +        elif k in nodes.Iir_Kinds.Subprogram_Declaration: +            bod = nodes.Get_Subprogram_Body(decl) +            if bod != nodes.Null_Iir: +                decl = bod + +        decl_loc = self.declaration_to_location(decl) +        if decl_loc is None: +            return None +        return [decl_loc]      def hover(self, doc_uri, position):          return self._docs[doc_uri].hover(position) | 
