diff options
Diffstat (limited to 'pyGHDL/lsp/document.py')
-rw-r--r-- | pyGHDL/lsp/document.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/pyGHDL/lsp/document.py b/pyGHDL/lsp/document.py index 2656606c6..1a6a20f39 100644 --- a/pyGHDL/lsp/document.py +++ b/pyGHDL/lsp/document.py @@ -9,6 +9,8 @@ import pyGHDL.libghdl.vhdl.nodes as nodes import pyGHDL.libghdl.vhdl.sem_lib as sem_lib import pyGHDL.libghdl.vhdl.sem as sem import pyGHDL.libghdl.vhdl.formatters as formatters +import pyGHDL.libghdl.vhdl.prints as prints +import pyGHDL.libghdl.file_comments as file_comments from . import symbols, references @@ -197,7 +199,34 @@ class Document(object): def goto_definition(self, position): loc = self.position_to_location(position) - return references.goto_definition(self._tree, loc) + return references.find_definition_by_loc(self._tree, loc) + + def hover(self, position): + loc = self.position_to_location(position) + t = references.find_definition_by_loc(self._tree, loc) + if t is None: + return None + + # Regenerate the declaration + hand = prints.Allocate_Handle() + prints.Print_String(t, hand) + buffer = prints.Get_C_String(hand) + buf_len = prints.Get_Length(hand) + if buf_len == 0: + res = None + else: + txt = '' + t_loc = nodes.Get_Location(t) + t_fe = files_map.Location_To_File(t_loc) + comm = file_comments.Find_First_Comment(t_fe, t) + while comm != file_comments.No_Comment_Index: + txt += file_comments.Get_Comment(t_fe, comm) + '\n' + comm = file_comments.Get_Next_Comment(t_fe, comm) + newtext = buffer[:buf_len].decode(Document.encoding) + txt += "```vhdl\n" + newtext + "\n```" + res = {'contents': { 'kind': 'markdown', 'value': txt }} + prints.Free_Handle(hand) + return res def format_range(self, rng): first_line = rng["start"]["line"] + 1 @@ -206,10 +235,10 @@ class Document(object): return None if self._tree == nodes.Null_Iir: return None - hand = formatters.Allocate_Handle() + hand = prints.Allocate_Handle() formatters.Indent_String(self._tree, hand, first_line, last_line) - buffer = formatters.Get_C_String(hand) - buf_len = formatters.Get_Length(hand) + buffer = prints.Get_C_String(hand) + buf_len = prints.Get_Length(hand) newtext = buffer[:buf_len].decode(Document.encoding) res = [ { @@ -220,5 +249,5 @@ class Document(object): "newText": newtext, } ] - formatters.Free_Handle(hand) + prints.Free_Handle(hand) return res |