Add Dart support to codebase indexing#941
Conversation
📝 WalkthroughWalkthroughDart 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. ChangesDart tree-sitter support
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
edelauna
left a comment
There was a problem hiding this comment.
Thanks so much for this contribution, had some comments regarding the queries.
e63a286 to
5f71794
Compare
|
Thanks for the detailed review. I addressed all three points in 8b19e9b:
The focused Dart and language-parser tests pass. |
There was a problem hiding this comment.
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 winRegister 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
📒 Files selected for processing (4)
src/services/tree-sitter/__tests__/fixtures/sample-dart.tssrc/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.tssrc/services/tree-sitter/index.tssrc/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
There was a problem hiding this comment.
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 winRegister Dart with the correct extension format.
path.extname(filePath)returns.dart, but this array addsdartwithout the leading dot. Consequently,parseSourceCodeDefinitionsForFilerejects every.dartfile 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
📒 Files selected for processing (2)
src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.dart.spec.tssrc/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
|
The latest CodeRabbit finding about the Dart extension format is a false positive. The entry in The Dart definition tests already exercise the public |
Related GitHub Issue
Closes: #940
Description
Adds Dart support to Tree-sitter-based codebase indexing.
.dartas a supported source extension and loadstree-sitter-dart.wasm..gitignoreor.rooignorewhen 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.tsExpected result: 2 test files and 8 tests pass.
The repository pre-commit and pre-push hooks were also run successfully:
Manual verification:
.dartfiles.Pre-Submission Checklist
Screenshots / Videos
Not applicable — this change has no UI impact.
Documentation Updates
Additional Notes
No generated-file suffixes such as
*.g.dartor*.freezed.dartare hard-coded into the exclusion logic. Existing.gitignoreand.rooignorebehavior remains the source of truth, preserving access to generated APIs when projects intentionally index them.Get in Touch
GitHub: @WebMad
Summary by CodeRabbit
.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.