[gemma4] first step
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"""
|
||||
Centralized constants for the Skill language parser and LSP server.
|
||||
"""
|
||||
|
||||
from typing import Final, Set
|
||||
|
||||
# Node types that represent syntax errors in Tree-sitter
|
||||
ERROR_NODE_TYPES: Final[Set[str]] = {"ERROR", "MISSING"}
|
||||
|
||||
# Node types that are considered significant enough to appear in the Document Symbol outline
|
||||
SYMBOLIC_NODE_TYPES: Final[Set[str]] = {
|
||||
"function_definition",
|
||||
"procedure_definition",
|
||||
"namespace",
|
||||
"let_binding",
|
||||
}
|
||||
|
||||
# Node types used to identify names/identifiers within symbolic nodes
|
||||
IDENTIFIER_NODE_TYPES: Final[Set[str]] = {"identifier", "name"}
|
||||
+4
-4
@@ -9,6 +9,7 @@ from lsprotocol.types import (
|
||||
SymbolKind,
|
||||
)
|
||||
from pygls.workspace import TextDocument
|
||||
from skillls.constants import ERROR_NODE_TYPES, IDENTIFIER_NODE_TYPES, SYMBOLIC_NODE_TYPES
|
||||
|
||||
class SkillParser:
|
||||
"""
|
||||
@@ -51,7 +52,7 @@ class SkillParser:
|
||||
"""Recursively traverses the AST to find errors and symbols."""
|
||||
|
||||
# 1. Handle Errors (Diagnostics)
|
||||
if node.type == "ERROR" or node.type == "MISSING":
|
||||
if node.type in ERROR_NODE_TYPES:
|
||||
start_point = node.start_point
|
||||
end_point = node.end_point
|
||||
|
||||
@@ -78,14 +79,13 @@ class SkillParser:
|
||||
|
||||
def _is_symbol_node(self, node) -> bool:
|
||||
"""Determines if a node is significant enough to be an outline symbol."""
|
||||
symbolic_types = {"function_definition", "procedure_definition", "namespace", "let_binding"}
|
||||
return node.type in symbolic_types or node.type.endswith("_def")
|
||||
return node.type in SYMBOLIC_NODE_TYPES or node.type.endswith("_def")
|
||||
|
||||
def _create_document_symbol(self, node, content: str) -> DocumentSymbol | None:
|
||||
"""Extracts a name and range for an AST node to create an LSP symbol."""
|
||||
name = None
|
||||
for child in node.children:
|
||||
if child.type == "identifier" or child.type == "name":
|
||||
if child.type in IDENTIFIER_NODE_TYPES:
|
||||
start_byte = child.start_byte
|
||||
end_byte = child.end_byte
|
||||
name = content[start_byte:end_byte]
|
||||
|
||||
Reference in New Issue
Block a user