diff --git a/server/src/tools/semantic_tokens.py b/server/src/tools/semantic_tokens.py index b35c155..597634d 100644 --- a/server/src/tools/semantic_tokens.py +++ b/server/src/tools/semantic_tokens.py @@ -4,7 +4,6 @@ from tclint.syntax_tree import Visitor, QuotedWord, Command, BareWord from tclint.commands import get_commands import attrs from common.load_data import standard_items -from tools.completion_items import completion import lsprotocol.types as lsp @@ -86,19 +85,23 @@ class _Highlighter(Visitor): pass def visit_bare_word(self, word: BareWord): - name = word.value - - in_standard = any(item.label == name for item in standard_items.nx_procs) - - in_custom = any(item.label == name for items in self.custom_functions.values() for item in items) - - if in_standard or in_custom: - line, col = word.pos - self._tokens.append((((line - 1, col - 1), len(name), "function", []))) + # Intentionally do not classify bare words as functions here. + # Function highlighting is handled in visit_command for the routine only, + # using completion items (custom functions) as the source of truth. + return def visit_command(self, command: Command): routine = command.routine + # Highlight functions (custom or standard) when used as the routine + name = getattr(routine, "contents", None) + if name: + in_custom = any(item.label == name for items in self.custom_functions.values() for item in items) + in_standard = any(item.label == name for item in standard_items.nx_procs) + if in_custom or in_standard: + line, col = routine.contents_pos + self._tokens.append((((line - 1, col - 1), len(name), "function", []))) + if routine.contents == "puts": line, col = routine.contents_pos self._tokens.append(