[gemma4] apply tree-sitter changes

This commit is contained in:
2026-06-19 11:02:15 +02:00
parent 3de76e196c
commit f56a94e35e
3 changed files with 146 additions and 24 deletions
+10 -19
View File
@@ -17,10 +17,9 @@ class SkillParser:
"""
def __init__(self):
# Initialize the language and parser using tree-sitter-skill bindings
self.language = tree_sitter_skill.language()
self.parser = Parser()
self.parser.set_language(self.language)
# Initialize the language and parser using tree_sitter_skill bindings
self.language = Language(tree_sitter_skill.language())
self.parser = Parser(self.language)
def parse_document(self, text_document: TextDocument) -> tuple[list[Diagnostic], list[DocumentSymbol]]:
"""
@@ -49,7 +48,7 @@ class SkillParser:
diagnostics: list[Diagnostic],
symbols: list[DocumentSymbol]
) -> None:
"""Recursively traverses the AST to find errors and significant nodes."""
"""Recursively traverses the AST to find errors and symbols."""
# 1. Handle Errors (Diagnostics)
if node.type == "ERROR" or node.type == "MISSING":
@@ -68,11 +67,6 @@ class SkillParser:
)
# 2. Handle Symbols (Document Symbols / Outline)
# Note: In a real implementation, we would check for specific node types
# like 'function_definition' or 'procedure'.
# Since the exact grammar is in the private repo, we use a pattern:
# If a node represents a definition, we extract its name.
if self._is_symbol_node(node):
symbol = self._create_document_symbol(node, content)
if symbol:
@@ -84,15 +78,11 @@ class SkillParser:
def _is_symbol_node(self, node) -> bool:
"""Determines if a node is significant enough to be an outline symbol."""
# This depends on the tree-sitter-skill grammar.
# We check for typical 'definition' or 'declaration' keywords/types.
# Placeholder logic: we look for nodes that aren't just primitive tokens.
symbolic_types = {"function_definition", "procedure_definition", "namespace", "let_binding"}
return node.type in symbolic_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."""
# Try to find an identifier child to use as the symbol name
name = None
for child in node.children:
if child.type == "identifier" or child.type == "name":
@@ -102,22 +92,23 @@ class SkillParser:
break
if not name:
# Fallback to the node type itself if no identifier is found
name = node.type
# Ensure name is a string for DocumentSymbol
symbol_name = str(name)
start_pt = node.start_point
end_pt = node.end_point
return DocumentSymbol(
name=name,
kind=SymbolKind.Function, # Defaulting to Function; would be more specific in real grammar
name=symbol_name,
kind=SymbolKind.Function,
range=Range(
start=Position(start_pt[0], start_pt[1]),
end=Position(end_pt[0], end_pt[1])
),
selection_range=Range(
start=Position(start_pt[0], start_pt[1]),
end=Position(start_pt[0], start_pt[1])
end=Position(end_pt[0], end_pt[1])
)
)
```