aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/lsp/document.py
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-01-26 18:27:30 +0100
committerTristan Gingold <tgingold@free.fr>2023-01-26 21:56:33 +0100
commit446f15d3b4b410fc7a9443a6bd010e8d1db735bd (patch)
tree2865d0161e04e97bac8f1e3dc89dcf9391330618 /pyGHDL/lsp/document.py
parentab3c672925cb214be9d732835e891557a511b173 (diff)
downloadghdl-446f15d3b4b410fc7a9443a6bd010e8d1db735bd.tar.gz
ghdl-446f15d3b4b410fc7a9443a6bd010e8d1db735bd.tar.bz2
ghdl-446f15d3b4b410fc7a9443a6bd010e8d1db735bd.zip
pyGHDL/lsp: update, handle hover
Diffstat (limited to 'pyGHDL/lsp/document.py')
-rw-r--r--pyGHDL/lsp/document.py39
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