Skip to content

feat(index): tree-sitter AST extraction + schema v3 edges table#356

Merged
ajianaz merged 2 commits into
developfrom
feat/tree-sitter-ast-v3-edges
Jul 22, 2026
Merged

feat(index): tree-sitter AST extraction + schema v3 edges table#356
ajianaz merged 2 commits into
developfrom
feat/tree-sitter-ast-v3-edges

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Phase 2 — Knowledge Graph: tree-sitter + edges table

What

  • tree-sitter AST parsing for Rust, Go, Python, TypeScript (feature-gated --features tree-sitter)
  • Schema v3: edges table with typed relationships (CALLS, IMPORTS, IMPLEMENTS, INHERITS, CHILD_OF)
  • Wiring: indexing pipeline populates edges table when tree-sitter is enabled

Why

  • Regex extraction misses structural info (inheritance, implementation, imports)
  • tree-sitter gives real AST with accurate symbol names and typed edges
  • edges table is a richer superset of call_graph for future graph queries

Changes

File Description
Cargo.toml tree-sitter feature flag + 5 optional deps
src/index/ast.rs NEW 960 lines: types, API, 4 language extractors, 10 tests
src/index/extract.rs Tree-sitter primary, regex fallback dispatch
src/index/schema.rs v3 migration: edges table + call_graph migration
src/index/graph.rs KgEdge, store_kg_edges, clear_kg_edges_for_file
src/index/mod.rs Wire edges population into indexing pipeline

Test results

  • Default (no tree-sitter): 705 pass, 0 fail
  • With --features tree-sitter: 714 pass, 0 fail (+9 new)
  • Clippy: 0 warnings both modes
  • Binary size: ~454KB release for 4 language grammars

Key technical decisions

  • tree-sitter 0.26: No descendants() method, uses cursor-based DFS
  • Kind-based child lookup: Grammars dont use named fields, find_child_by_kind() helper
  • TS export_statement: Grammar wraps exports, recursive unwrapping needed
  • Backward compatible: call_graph table preserved, edges is additive
  • Zero overhead: Default build has no tree-sitter code compiled

ajianaz added 2 commits July 22, 2026 21:11
Phase 2 of knowledge graph implementation.

## tree-sitter AST extraction (feature-gated)

- Add ast.rs module with tree-sitter-based AST parsing for Rust, Go,
  Python, TypeScript
- Cursor-based DFS traversal (tree-sitter 0.26 has no descendants())
- Kind-based child lookup (grammars lack named fields like name)
- TypeScript export_statement unwrapping for exported declarations
- Go const/var declaration support via const_spec/var_spec traversal
- Wire extract_symbols() and extract_calls() to try tree-sitter
  first, fall back to regex for unsupported languages
- Add extract_edges() for richer edge types (IMPORTS, IMPLEMENTS,
  INHERITS, CHILD_OF)
- 10 new tests covering all 4 language extractors

## Schema v3 — edges table

- Add edges table: source to target with typed relationship
  (CALLS, IMPORTS, IMPLEMENTS, INHERITS, CHILD_OF)
- Migrate existing call_graph data into edges with kind=CALLS
- Populate edges table during indexing when tree-sitter feature enabled
- Add KgEdge, store_kg_edges(), clear_kg_edges_for_file() to graph.rs
- 2 new schema migration tests

## Feature flag

- All tree-sitter code behind --features tree-sitter
- Default build has zero tree-sitter overhead
- 4 language grammars statically linked (~454KB release binary)

Test results:
- Default: 705 pass, 0 fail
- With tree-sitter: 714 pass, 0 fail (+9 new tests)
- Clippy: 0 warnings both modes
@ajianaz
ajianaz merged commit 20308fc into develop Jul 22, 2026
10 checks passed
@ajianaz
ajianaz deleted the feat/tree-sitter-ast-v3-edges branch July 22, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant