Skip to content

Add Dart support to codebase indexing#941

Open
WebMad wants to merge 3 commits into
Zoo-Code-Org:mainfrom
WebMad:feat/940-dart-codebase-indexing
Open

Add Dart support to codebase indexing#941
WebMad wants to merge 3 commits into
Zoo-Code-Org:mainfrom
WebMad:feat/940-dart-codebase-indexing

Conversation

@WebMad

@WebMad WebMad commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #940

Description

Adds Dart support to Tree-sitter-based codebase indexing.

  • Registers .dart as a supported source extension and loads tree-sitter-dart.wasm.
  • Adds a Dart definitions query adapted from tree-sitter-dart's canonical tags query.
  • Captures classes, methods, constructors, factory and const constructors, getters, setters, operators, mixins, extensions, extension types, enums, type aliases, and top-level functions.
  • Adds focused parser and definition-extraction coverage using representative Dart declarations.
  • Keeps generated Dart files indexable; projects can continue excluding generated output through .gitignore or .rooignore when desired.

Reviewers should pay particular attention to the query patterns for constructors and top-level accessors, which differ structurally from class method signatures in the Dart grammar.

Test Procedure

Automated tests:

cd src
npx vitest run services/tree-sitter/__tests__/languageParser.spec.ts services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts

Expected result: 2 test files and 8 tests pass.

The repository pre-commit and pre-push hooks were also run successfully:

  • ESLint across all workspace packages.
  • TypeScript type-checking across all workspace packages.

Manual verification:

  1. Open a Dart or Flutter workspace containing .dart files.
  2. Rebuild the codebase index.
  3. Search for a Dart class, mixin, enum, extension, constructor, getter/setter, or top-level function.
  4. Confirm that the corresponding Dart definition is returned as indexed context.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Not applicable — this change has no UI impact.

Documentation Updates

  • No documentation updates are required.
  • Yes, documentation updates are required. (Please describe what needs to be updated or link to a PR in the docs repository).

Additional Notes

No generated-file suffixes such as *.g.dart or *.freezed.dart are hard-coded into the exclusion logic. Existing .gitignore and .rooignore behavior remains the source of truth, preserving access to generated APIs when projects intentionally index them.

Get in Touch

GitHub: @WebMad

Summary by CodeRabbit

  • New Features
    • Added Dart (.dart) support for source-code definition parsing, including Dart query coverage for classes, types, methods/constructors (including redirecting factories), mixins, extensions (including extension types), enums, and top-level functions/getters/setters.
  • Bug Fixes
    • Improved definition range extraction to better include multiline bodies and avoid duplicate declaration lines.
  • Tests
    • Added Dart fixture parsing, validated Dart parser/query loading, and expanded the Dart definition parsing suite (including redirecting constructors and exclusion of nested/local functions).

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Dart is added to tree-sitter’s supported extensions, parser loading, query exports, and definition extraction. Tests and a representative Dart fixture cover declarations, constructors, mixins, enums, extensions, typedefs, and functions.

Changes

Dart tree-sitter support

Layer / File(s) Summary
Dart query and parser registration
src/services/tree-sitter/queries/dart.ts, src/services/tree-sitter/queries/index.ts, src/services/tree-sitter/languageParser.ts, src/services/tree-sitter/index.ts
Adds Dart capture patterns, exports the query, loads the Dart grammar and query, and recognizes .dart files.
Dart definition extraction
src/services/tree-sitter/index.ts
Includes adjacent function bodies and prevents duplicate declaration context when parent and definition nodes start on the same line.
Dart parsing fixtures and validation
src/services/tree-sitter/__tests__/fixtures/sample-dart.ts, src/services/tree-sitter/__tests__/languageParser.spec.ts, src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts
Adds representative Dart source and verifies parser loading and extracted declarations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: hannesrudolph

Sequence Diagram(s)

sequenceDiagram
  participant DartFile
  participant loadRequiredLanguageParsers
  participant DartWasm
  participant Query
  participant DefinitionParser
  DartFile->>loadRequiredLanguageParsers: provide .dart extension
  loadRequiredLanguageParsers->>DartWasm: load Dart grammar
  loadRequiredLanguageParsers->>Query: construct query from dartQuery
  Query-->>loadRequiredLanguageParsers: return Dart query
  DefinitionParser->>Query: extract Dart definitions
  Query-->>DefinitionParser: return captured declarations
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: adding Dart support to codebase indexing.
Description check ✅ Passed The PR description matches the template with issue link, implementation summary, tests, checklist, and extra notes.
Linked Issues check ✅ Passed The changes satisfy #940 by adding .dart support, Dart queries/parsers, and tests for common Dart constructs.
Out of Scope Changes check ✅ Passed The added fixture, query, parser, and test updates all support Dart indexing and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 18, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this contribution, had some comments regarding the queries.

Comment thread src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts Outdated
Comment thread src/services/tree-sitter/queries/dart.ts Outdated
Comment thread src/services/tree-sitter/queries/dart.ts
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 19, 2026
@WebMad
WebMad force-pushed the feat/940-dart-codebase-indexing branch from e63a286 to 5f71794 Compare July 22, 2026 08:44
@WebMad

WebMad commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. I addressed all three points in 8b19e9b:

  • strengthened the Dart assertions with line-range prefixes and an exact definition count;
  • restored the upstream method_signature fallback and removed redundant patterns;
  • removed the conflicting wrapped constructor capture and added a multiline-constructor regression test.

The focused Dart and language-parser tests pass.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/services/tree-sitter/index.ts (1)

96-97: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Register the dotted extension and cover the public routing path.

path.extname() returns .dart (Line 113), but Line 97 adds "dart"; strict matching at Line 115 rejects every Dart file before parser loading.

  • src/services/tree-sitter/index.ts#L96-L97: replace "dart" with ".dart".
  • src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts#L12-L111: add a regression assertion through the extension allowlist/public entry point so this mismatch cannot recur.
Proposed fix
-	"dart",
+	".dart",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/tree-sitter/index.ts` around lines 96 - 97, Update the Dart
extension entry in the tree-sitter allowlist in
src/services/tree-sitter/index.ts:96-97 from the bare name to the dotted form
expected by path.extname(). In
src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts:12-111,
add a regression assertion through the public parseSourceCodeDefinitions routing
path that confirms Dart files are accepted and parsed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/services/tree-sitter/index.ts`:
- Around line 96-97: Update the Dart extension entry in the tree-sitter
allowlist in src/services/tree-sitter/index.ts:96-97 from the bare name to the
dotted form expected by path.extname(). In
src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts:12-111,
add a regression assertion through the public parseSourceCodeDefinitions routing
path that confirms Dart files are accepted and parsed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 56743d1c-2c80-472e-90a0-7674176c63bb

📥 Commits

Reviewing files that changed from the base of the PR and between 5f71794 and 8b19e9b.

📒 Files selected for processing (4)
  • src/services/tree-sitter/__tests__/fixtures/sample-dart.ts
  • src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts
  • src/services/tree-sitter/index.ts
  • src/services/tree-sitter/queries/dart.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/services/tree-sitter/tests/fixtures/sample-dart.ts
  • src/services/tree-sitter/queries/dart.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/services/tree-sitter/index.ts (1)

96-97: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Register Dart with the correct extension format.

path.extname(filePath) returns .dart, but this array adds dart without the leading dot. Consequently, parseSourceCodeDefinitionsForFile rejects every .dart file at its supported-extension check before loading the Dart parser. Change this entry to ".dart" or normalize both sides consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/tree-sitter/index.ts` around lines 96 - 97, Update the Dart
entry in the supported extensions array used by
parseSourceCodeDefinitionsForFile to include the leading dot returned by
path.extname, ensuring .dart files pass the extension check and reach the Dart
parser.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/services/tree-sitter/index.ts`:
- Around line 96-97: Update the Dart entry in the supported extensions array
used by parseSourceCodeDefinitionsForFile to include the leading dot returned by
path.extname, ensuring .dart files pass the extension check and reach the Dart
parser.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0d80a0c4-4b43-4764-8d23-f86d94887a29

📥 Commits

Reviewing files that changed from the base of the PR and between 8b19e9b and 4100784.

📒 Files selected for processing (2)
  • src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.ts
  • src/services/tree-sitter/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/services/tree-sitter/tests/parseSourceCodeDefinitions.dart.spec.ts

@WebMad

WebMad commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

The latest CodeRabbit finding about the Dart extension format is a false positive.

The entry in src/services/tree-sitter/index.ts is intentionally "dart" because the entire array is normalized immediately afterward with .map((e) => .${e}). The resulting value is therefore .dart, which correctly matches path.extname(filePath). Changing the entry to ".dart" as suggested would produce "..dart" and break routing.

The Dart definition tests already exercise the public parseSourceCodeDefinitionsForFile() path via testParseSourceCodeDefinitions(), including the extension allowlist check. I also ran the focused tests (14/14 passing) and the complete tree-sitter test suite (305 passing, 12 skipped). No code change is needed for this finding.

@WebMad
WebMad requested a review from edelauna July 22, 2026 11:21
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-author PR is waiting for the author to address requested changes labels Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Add Dart support to codebase indexing

2 participants