fix: wrong highligthing

This commit is contained in:
Christoph Brandau
2025-08-12 13:18:08 +02:00
parent 480978d6bb
commit e20bb85ac6
+13 -10
View File
@@ -4,7 +4,6 @@ from tclint.syntax_tree import Visitor, QuotedWord, Command, BareWord
from tclint.commands import get_commands from tclint.commands import get_commands
import attrs import attrs
from common.load_data import standard_items from common.load_data import standard_items
from tools.completion_items import completion
import lsprotocol.types as lsp import lsprotocol.types as lsp
@@ -86,19 +85,23 @@ class _Highlighter(Visitor):
pass pass
def visit_bare_word(self, word: BareWord): def visit_bare_word(self, word: BareWord):
name = word.value # Intentionally do not classify bare words as functions here.
# Function highlighting is handled in visit_command for the routine only,
in_standard = any(item.label == name for item in standard_items.nx_procs) # using completion items (custom functions) as the source of truth.
return
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", [])))
def visit_command(self, command: Command): def visit_command(self, command: Command):
routine = command.routine 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": if routine.contents == "puts":
line, col = routine.contents_pos line, col = routine.contents_pos
self._tokens.append( self._tokens.append(