Skip to content

fix(ai): the AST engine parses with tree-sitter - #562

Merged
dan-petty merged 1 commit into
release/v0.2.23from
fix/538-tree-sitter-grammars
Sep 25, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.23from
fix/538-tree-sitter-grammars

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Closes #538.

Problem

TreeSitterEngine maps TypeScript, JavaScript, Go, Rust, Java and HCL with tree-sitter, but neither tree_sitter nor any grammar was a dependency, so every file fell back to the regex parser. In the pinned samples, 16 of 31 TypeScript, 10 of 37 Rust, 8 of 85 Java and 1 of 5 HCL files yielded no symbols.

Changes

  • Dependencies: tree-sitter plus the official grammars (python, typescript, javascript, go, rust, java) and tree-sitter-hcl from tree-sitter-grammars.
  • Grammar loading: LANG_TO_GRAMMAR pairs each language with its package and entry point. TypeScript's language_typescript and language_tsx are separate grammars, so .tsx gets the JSX-aware one. grammar.language() didn't exist for TypeScript, so loading had been failing silently.
  • Newly recognised declarations:
    • TS/JS: arrow-function declarators (const f = () =>), type aliases, enums, abstract classes;
    • Go: type specs, as struct, interface or type;
    • Rust: enums, type aliases, unions, modules, constants, statics, macro_rules!;
    • Java: enums, records, constructors, annotation types and their elements;
    • HCL: top-level blocks, named as the fallback names them (resource "aws_vpc" "this"), nested blocks excluded.
  • Accurate reporting: a file tree-sitter parses with no symbols (and where the fallback also finds none) is reported as parsed by tree-sitter.

Verification on the pinned samples

Category Parser before → after Symbols before → after Files without symbols after
TypeScript/JavaScript fallback → tree-sitter 37/37 54 → 194 0 (was 16)
Go fallback → tree-sitter 5/5 191 → 195 0
Rust fallback → tree-sitter 37/37 763 → 1,552 1 re-export file (was 10)
Java fallback → tree-sitter 85/85 1,649 → 1,077 5 package-info.java (was 8)
Terraform fallback → tree-sitter 5/5 439 → 457 0 (was 1)

Java's count fell because the regex over-counted: it reported 80 methods in Gson.java, where tree-sitter finds 38 methods and 2 constructors. Repository maps grew from 102 to 126 files for TS/JS, and from 41 to 64 for Terraform.

Test plan

  • tests/test_treesitter_native_symbols.py (8 tests):
    • native parsing with every new declaration kind, per language;
    • TSX;
    • nested Terraform blocks excluded;
    • a file that declares nothing.
  • tests/test_treesitter_engine.py: .tsx now detects as tsx
  • uv run devops ci --force: all 13 gates pass

TreeSitterEngine mapped TypeScript, JavaScript, Go, Rust, Java and HCL with tree-sitter,
but neither tree_sitter nor any grammar was a dependency, so every file went to the regex
fallback. In the pinned samples, 16 of 31 TypeScript and 10 of 37 Rust files yielded no
symbols.

tree-sitter and the official grammars are now dependencies. Each language loads by its
package's entry point; TypeScript and TSX are separate grammars, and
`grammar.language()` did not exist for TypeScript. The native walk names:
- arrow-function declarators;
- Go type specs;
- Rust enums, modules, constants and macros;
- Java enums, records, constructors and annotations;
- top-level Terraform blocks.

A file tree-sitter parses with no symbols is reported as parsed.

On the samples, every file in those languages parses with tree-sitter. TypeScript
symbols rose from 54 to 194 and Rust from 763 to 1,552.

Closes #538
@dan-petty dan-petty added this to the v0.2.23 milestone Sep 25, 2026
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/ai AI review pipeline, personas, prompts, LLM client, or RAG priority/p1-high Priority P1: high-impact work for the next planned milestone labels Sep 25, 2026
@dan-petty
dan-petty merged commit e7ac37f into release/v0.2.23 Sep 25, 2026
7 checks passed
@dan-petty
dan-petty deleted the fix/538-tree-sitter-grammars branch September 25, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1-high Priority P1: high-impact work for the next planned milestone scope/ai AI review pipeline, personas, prompts, LLM client, or RAG type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant