Tree Sitter Upgrade #5
+27
-23
@@ -44,38 +44,42 @@ class SkillParser:
|
|||||||
|
|
||||||
def _traverse_tree(
|
def _traverse_tree(
|
||||||
self,
|
self,
|
||||||
node,
|
root_node,
|
||||||
content: str,
|
content: str,
|
||||||
diagnostics: list[Diagnostic],
|
diagnostics: list[Diagnostic],
|
||||||
symbols: list[DocumentSymbol]
|
symbols: list[DocumentSymbol]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Recursively traverses the AST to find errors and symbols."""
|
"""Iteratively traverses the AST to find errors and symbols."""
|
||||||
|
stack = [root_node]
|
||||||
|
|
||||||
# 1. Handle Errors (Diagnostics)
|
while stack:
|
||||||
if node.type in ERROR_NODE_TYPES:
|
node = stack.pop()
|
||||||
start_point = node.start_point
|
|
||||||
end_point = node.end_point
|
|
||||||
|
|
||||||
diagnostics.append(
|
# 1. Handle Errors (Diagnostics)
|
||||||
Diagnostic(
|
if node.type in ERROR_NODE_TYPES:
|
||||||
range=Range(
|
start_point = node.start_point
|
||||||
start=Position(start_point[0], start_point[1]),
|
end_point = node.end_point
|
||||||
end=Position(end_point[0], end_point[1])
|
|
||||||
),
|
diagnostics.append(
|
||||||
message=f"Syntax error: unexpected {node.type} token",
|
Diagnostic(
|
||||||
severity=DiagnosticSeverity.Error,
|
range=Range(
|
||||||
|
start=Position(start_point[0], start_point[1]),
|
||||||
|
end=Position(end_point[0], end_point[1])
|
||||||
|
),
|
||||||
|
message=f"Syntax error: unexpected {node.type} token",
|
||||||
|
severity=DiagnosticSeverity.Error,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# 2. Handle Symbols (Document Symbols / Outline)
|
# 2. Handle Symbols (Document Symbols / Outline)
|
||||||
if self._is_symbol_node(node):
|
if self._is_symbol_node(node):
|
||||||
symbol = self._create_document_symbol(node, content)
|
symbol = self._create_document_symbol(node, content)
|
||||||
if symbol:
|
if symbol:
|
||||||
symbols.append(symbol)
|
symbols.append(symbol)
|
||||||
|
|
||||||
# 3. Continue traversal
|
# 3. Continue traversal - push children in reverse order to maintain original DFS order
|
||||||
for child in node.children:
|
for child in reversed(node.children):
|
||||||
self._traverse_tree(child, content, diagnostics, symbols)
|
stack.append(child)
|
||||||
|
|
||||||
def _is_symbol_node(self, node) -> bool:
|
def _is_symbol_node(self, node) -> bool:
|
||||||
"""Determines if a node is significant enough to be an outline symbol."""
|
"""Determines if a node is significant enough to be an outline symbol."""
|
||||||
|
|||||||
Reference in New Issue
Block a user