From 31cb644f85e7f5088c4017941faf095a578b9fb8 Mon Sep 17 00:00:00 2001 From: christoph_xd Date: Sun, 20 Jul 2025 17:17:38 +0200 Subject: [PATCH] del tokens --- server/src/common/tokens.py | 81 ------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 server/src/common/tokens.py diff --git a/server/src/common/tokens.py b/server/src/common/tokens.py deleted file mode 100644 index b2cea98..0000000 --- a/server/src/common/tokens.py +++ /dev/null @@ -1,81 +0,0 @@ -# tokens.py -from typing import List -import attrs -import enum -from lark import Tree, Token - -# Legend must match the client -SEMANTIC_TOKEN_TYPES = { - "keyword": 0, - "variable": 2, - "string": 3, -} -SEMANTIC_TOKEN_MODIFIERS = { - "declaration": 1 << 0, -} - - -class TokenModifier(enum.IntFlag): - deprecated = enum.auto() - readonly = enum.auto() - defaultLibrary = enum.auto() - definition = enum.auto() - - -@attrs.define -class TokenData: - line: int - offset: int - text: str - - tok_type: str = "" - tok_modifiers: List[TokenModifier] = attrs.field(factory=list) - - -TokenTypes = ["keyword", "variable", "function", "operator", "parameter", "type"] - - -def collect_semantic_tokens(tree: Tree) -> list[int]: - """ - Walk the parse tree and return a flat LSP semanticTokens/full array: - [line, char, length, tokenType, tokenModifiers, …] - """ - data = [] - for tok in tree.scan_values(lambda v: isinstance(v, Token)): - # 'set' keyword - if tok.type == "SET": - data.append( - [ - tok.line - 1, - tok.column - 1, - len(tok.value), - SEMANTIC_TOKEN_TYPES["keyword"], - 0, - ] - ) - # variable being declared - elif tok.type == "NAME": - data.append( - [ - tok.line - 1, - tok.column - 1, - len(tok.value), - SEMANTIC_TOKEN_TYPES["variable"], - SEMANTIC_TOKEN_MODIFIERS["declaration"], - ] - ) - # string literal - elif tok.type == "STRING": - data.append( - [ - tok.line - 1, - tok.column - 1, - len(tok.value), - SEMANTIC_TOKEN_TYPES["string"], - 0, - ] - ) - - # sort by position and flatten - data.sort(key=lambda x: (x[0], x[1])) - return [p for token in data for p in token]