diff --git a/server/src/tools/semantic_tokens.py b/server/src/tools/semantic_tokens.py index dc1a6f5..b2f762e 100644 --- a/server/src/tools/semantic_tokens.py +++ b/server/src/tools/semantic_tokens.py @@ -45,6 +45,37 @@ class _Highlighter(Visitor): self._tokens = [] self.log_to_output = log_to_output + def _get_token_info(self, node): + """Hilfsmethode um Token-Informationen aus verschiedenen Node-Typen zu extrahieren.""" + if not hasattr(node, "pos"): + return None + + # Einfacher Fall: Node hat direkten value + if hasattr(node, "value") and node.value is not None: + line, col = node.pos + return (line - 1, col - 1), len(node.value) + + # CompoundBareWord: versuche erstes Segment + if hasattr(node, "children") and node.children: + first_segment = node.children[0] + if ( + hasattr(first_segment, "value") + and first_segment.value is not None + and hasattr(first_segment, "pos") + ): + line, col = first_segment.pos + return (line - 1, col - 1), len(first_segment.value) + + # Fallback: Gesamtlänge aus Positionen berechnen + if hasattr(node, "end_pos"): + start_line, start_col = node.pos + end_line, end_col = node.end_pos + if start_line == end_line: + length = end_col - start_col + return (start_line - 1, start_col - 1), length + + return None + def visit_quoted_word(self, word: QuotedWord): if not word.contents: return @@ -78,13 +109,14 @@ class _Highlighter(Visitor): ) if routine.contents == "set" and command.args: first_arg = command.args[0] - if hasattr(first_arg, "pos") and hasattr(first_arg, "value"): - line, col = first_arg.pos + token_info = self._get_token_info(first_arg) + if token_info: + (line, col), length = token_info self._tokens.append( ( ( - (line - 1, col - 1), - len(first_arg.value), + (line, col), + length, "variable", [TokenModifier.declaration], )