feat(core): add Dart language support#415
Open
junddao wants to merge 2 commits into
Open
Conversation
Adds Dart to the tree-sitter pipeline so Flutter/Dart codebases get the
same structural analysis (functions, classes, imports/exports) other
languages already enjoy.
- New `dartConfig` registered in the language registry (`.dart` ext,
Dart-flavored concepts and file patterns).
- New `DartExtractor` mapping tree-sitter-dart's grammar to the shared
StructuralAnalysis shape:
* top-level `function_signature` / getter / setter → functions
* `class_definition` / `mixin_declaration` / `extension_declaration`
/ `enum_declaration` → classes (methods + properties + enum constants)
* `library_import` / `library_export` (wrapped in `import_or_export`)
→ imports, with `_`-prefix visibility convention for exports.
- Adds `tree-sitter-dart` 1.0.0 as a dependency. Its npm-published WASM
ships an outdated dylink format that fails to load against
web-tree-sitter 0.26.x, so we also bundle a freshly rebuilt WASM at
`wasm-grammars/tree-sitter-dart.wasm` and teach `TreeSitterPlugin` to
fall back to bundled grammars when the npm copy is missing or stale.
- Tests: adds DartExtractor unit tests covering imports, top-level
functions, classes/mixins/enums, and the `_`-prefix visibility rule;
updates the language-registry built-in count from 40 → 41.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Dart to the tree-sitter pipeline so Flutter/Dart codebases get the same structural analysis (functions, classes, imports/exports) other languages already enjoy.
What's in this PR
dartConfigregistered in the language registry (.dartext, Dart-flavored concepts and file patterns).DartExtractormapping tree-sitter-dart's grammar to the sharedStructuralAnalysisshape:function_signature/ getter / setter → functionsclass_definition/mixin_declaration/extension_declaration/enum_declaration→ classes (methods + properties + enum constants)library_import/library_export(wrapped inimport_or_export) → imports, with the_-prefix Dart visibility convention for exportstree-sitter-dart@^1.0.0as a dependency. Its npm-published WASM ships an outdated dylink format that fails to load againstweb-tree-sitter0.26.x, so this PR also bundles a freshly rebuilt WASM atunderstand-anything-plugin/packages/core/wasm-grammars/tree-sitter-dart.wasmand teachesTreeSitterPluginto fall back to bundled grammars when the npm copy is missing or stale. The fallback mechanism is generic — any future grammar with a similar issue can drop a WASM intowasm-grammars/and benefit from it.DartExtractorunit tests covering imports, top-level functions, classes/mixins/enums, and the_-prefix visibility rule; updates the language-registry built-in count from 40 → 41.Notes
extractCallGraphreturns[]for Dart on purpose. tree-sitter-dart does not expose a singlecall_expressionnode — calls are encoded via chainedidentifier+argument_partselectors, which require nontrivial heuristics to disambiguate from member access. Semantic call relationships are still surfaced by the LLM-side analysis. Happy to follow up with a separate PR if maintainers want a structural call graph.extension on Foo { ... }) get a synthetic name (_AnonymousExtension_<line>) so they don't collide; they are not added toexports.Linked issue(s)
N/A
How I tested this
pnpm lintpnpm --filter @understand-anything/core test— 678/678 passing (added 8 new DartExtractor unit tests)pnpm test— 201/201 passingTreeSitterPlugintransparently uses the bundledwasm-grammars/tree-sitter-dart.wasmand Dart parsing succeeds.Versioning