-
Notifications
You must be signed in to change notification settings - Fork 199
Add Dart support to codebase indexing #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| export default `abstract class Animal { | ||
| String speak(); | ||
| } | ||
|
|
||
| class Point { | ||
| const Point(); | ||
| Point.named(); | ||
| factory Point.origin() => const Point(); | ||
|
|
||
| int get x => 0; | ||
| set x(int value) {} | ||
|
|
||
| Point operator +(Point other) => this; | ||
| } | ||
|
|
||
| mixin Runner { | ||
| void run() { | ||
| print("running"); | ||
| } | ||
| } | ||
|
|
||
| enum Status { | ||
| ready, | ||
| running; | ||
|
|
||
| const Status(); | ||
| } | ||
|
|
||
| class Dog extends Animal with Runner { | ||
| final String name; | ||
|
|
||
| Dog(this.name); | ||
|
|
||
| @override | ||
| String speak() { | ||
| return "\$name barks"; | ||
| } | ||
| } | ||
|
|
||
| extension StringTools on String { | ||
| String doubled() { | ||
| return this + this; | ||
| } | ||
| } | ||
|
|
||
| extension type UserId(int value) { | ||
| UserId.zero() : value = 0; | ||
| } | ||
|
|
||
| typedef Operation = int Function(int left, int right); | ||
|
|
||
| int get answer => 42; | ||
| set answer(int value) {} | ||
|
|
||
| int add(int left, int right) { | ||
| return left + right; | ||
| } | ||
| ` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { dartQuery } from "../queries" | ||
| import { testParseSourceCodeDefinitions } from "./helpers" | ||
| import sampleDartContent from "./fixtures/sample-dart" | ||
|
|
||
| const dartOptions = { | ||
| language: "dart", | ||
| wasmFile: "tree-sitter-dart.wasm", | ||
| queryString: dartQuery, | ||
| extKey: "dart", | ||
| } | ||
|
|
||
| describe("parseSourceCodeDefinitionsForFile with Dart", () => { | ||
| it("should capture common Dart declarations", async () => { | ||
| const result = await testParseSourceCodeDefinitions("/test/file.dart", sampleDartContent, dartOptions) | ||
|
|
||
| expect(result).toMatch(/abstract class Animal/) | ||
| expect(result).toMatch(/class Point/) | ||
| expect(result).toMatch(/const Point\(\)/) | ||
| expect(result).toMatch(/Point\.named\(\)/) | ||
| expect(result).toMatch(/factory Point\.origin\(\)/) | ||
| expect(result).toMatch(/int get x/) | ||
| expect(result).toMatch(/set x\(int value\)/) | ||
| expect(result).toMatch(/Point operator \+/) | ||
| expect(result).toMatch(/mixin Runner/) | ||
| expect(result).toMatch(/enum Status/) | ||
| expect(result).toMatch(/const Status\(\)/) | ||
| expect(result).toMatch(/class Dog extends Animal with Runner/) | ||
| expect(result).toMatch(/extension StringTools on String/) | ||
| expect(result).toMatch(/extension type UserId/) | ||
| expect(result).toMatch(/typedef Operation/) | ||
| expect(result).toMatch(/int get answer/) | ||
| expect(result).toMatch(/set answer\(int value\)/) | ||
| expect(result).toMatch(/String speak\(\)/) | ||
| expect(result).toMatch(/int add\(int left, int right\)/) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Definition captures adapted from tree-sitter-dart's canonical tags query: | ||
| // https://github.com/UserNobody14/tree-sitter-dart/blob/master/queries/tags.scm | ||
| export default ` | ||
| (class_definition | ||
| name: (identifier) @name) @definition.class | ||
|
|
||
| (method_signature | ||
| (function_signature)) @definition.method | ||
|
|
||
| (type_alias | ||
| (type_identifier) @name) @definition.type | ||
|
|
||
| (method_signature | ||
| (getter_signature | ||
| name: (identifier) @name)) @definition.method | ||
|
|
||
| (method_signature | ||
| (setter_signature | ||
| name: (identifier) @name)) @definition.method | ||
|
|
||
| (method_signature | ||
| (function_signature | ||
| name: (identifier) @name)) @definition.method | ||
|
|
||
| (method_signature | ||
| (factory_constructor_signature | ||
| (identifier) @name)) @definition.method | ||
|
|
||
| (method_signature | ||
| (constructor_signature | ||
| name: (identifier) @name)) @definition.method | ||
|
|
||
| (method_signature | ||
| (operator_signature)) @definition.method | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The upstream Was this intentionally omitted, or an oversight from the adaptation? |
||
|
|
||
| (constructor_signature | ||
| name: (identifier) @name) @definition.method | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is also a For the single-line constructors in the fixture this is fine — both nodes share the same Is there a case where a |
||
|
|
||
| (constant_constructor_signature | ||
| (identifier) @name) @definition.method | ||
|
|
||
| (mixin_declaration | ||
| (mixin) | ||
| (identifier) @name) @definition.mixin | ||
|
|
||
| (extension_declaration | ||
| name: (identifier) @name) @definition.extension | ||
|
|
||
| (extension_type_declaration | ||
| name: (identifier) @name) @definition.extension | ||
|
|
||
| (enum_declaration | ||
| name: (identifier) @name) @definition.enum | ||
|
|
||
| (program | ||
| (getter_signature | ||
| name: (identifier) @name) @definition.function) | ||
|
|
||
| (program | ||
| (setter_signature | ||
| name: (identifier) @name) @definition.function) | ||
|
|
||
| (function_signature | ||
| name: (identifier) @name) @definition.function | ||
| ` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertions here match substrings of the echoed source line (the pipeline outputs
lines[startLine], the raw source text). That means a mutation breaking every@namecapture in the query would still pass all 19 assertions — the@definition.*captures alone are enough to echo the source line.Sibling specs address this with two additions:
\d+--\d+ \|line-range prefix, which at least confirms the output came through the pipeline in the right format:expect(result).toMatch(/\d+--\d+ \| abstract class Animal/)expect(result!.split("\n").filter(l => l.includes(" | ")).length).toBe(N)One thing I wasn't sure about:
getMinComponentLines()defaults to 4, so single-line declarations likeconst Point()andint get x => 0would normally be filtered by thelineCount < 4check. Are assertions liketoMatch(/const Point\(\)/)expected to pass, and if so through which code path?