This commit is contained in:
Christoph Brandau
2025-08-01 13:35:02 +02:00
parent 98e2d104a8
commit 5e2e85830b
6 changed files with 178 additions and 9 deletions
+25 -2
View File
@@ -1,4 +1,4 @@
from tclint.syntax_tree import Visitor
from tclint.syntax_tree import Visitor, Command, BareWord, List
import lsprotocol.types as lsp
@@ -19,15 +19,21 @@ class _Completion(Visitor):
def __init__(self):
super().__init__()
self._custom_functions: list[lsp.CompletionItem] = []
self._proc_signatures = {}
@property
def custom_functions(self) -> list[lsp.CompletionItem]:
return self._custom_functions
@property
def proc_signatures(self):
return self._proc_signatures
def reset(self):
self._custom_functions = []
self._proc_signatures = {}
def visit_command(self, command):
def visit_command(self, command: Command):
routine = command.routine
if routine.contents == "proc" and command.args:
@@ -40,6 +46,23 @@ class _Completion(Visitor):
label=first_arg.value, kind=lsp.CompletionItemKind.Function
)
)
if len(command.args) < 2:
return
param_list_node = command.args[1]
if not hasattr(param_list_node, "children"):
return
param_names = []
for arg in param_list_node.children:
if isinstance(arg, BareWord):
param_names.append(arg.value)
elif isinstance(arg, List) and len(arg.children) >= 1:
first = arg.children[0]
if isinstance(first, BareWord):
param_names.append(first.value)
self._proc_signatures[first_arg.value] = param_names
completion = _Completion()