diff --git a/queries/highlights.scm b/queries/highlights.scm index d51e323..ed02410 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -2,11 +2,18 @@ ; Methods ; -------------------- -;; TODO: does not work -;(function_type - ;name: (identifier) @method) (super) @function +; TODO: add method/call_expression to grammar and +; distinguish method call from variable access +(function_expression_body + (identifier) @function) + +; NOTE: This query is a bit of a work around for the fact that the dart grammar doesn't +; specifically identify a node as a function call +(((identifier) @function (#match? @function "^_?[a-z]")) + . (selector . (argument_part))) @function + ; Annotations ; -------------------- (annotation @@ -87,17 +94,16 @@ (scoped_identifier scope: (identifier) @type) (function_signature - name: (identifier) @method) + name: (identifier) @function) (getter_signature - (identifier) @method) + (identifier) @function) (setter_signature - name: (identifier) @method) + name: (identifier) @function) (enum_declaration name: (identifier) @type) (enum_constant name: (identifier) @type) (type_identifier) @type -(void_type) @type ((scoped_identifier scope: (identifier) @type @@ -112,19 +118,36 @@ (inferred_type) @keyword ((identifier) @type - (#match? @type "^_?[A-Z]")) + (#match? @type "^_?[A-Z].*[a-z]")) ("Function" @type) -(void_type) @type (this) @variable.builtin ; properties -; TODO: add method/call_expression to grammar and -; distinguish method call from variable access +(expression_statement + (selector + (unconditional_assignable_selector + (identifier) @function)) + (selector (argument_part (arguments))) +) +(expression_statement + (cascade_section + (cascade_selector (identifier) @function) + (argument_part (arguments)) + ) +) + (unconditional_assignable_selector (identifier) @property) +(conditional_assignable_selector + (identifier) @property) + +(cascade_section + (cascade_selector + (identifier) @property)) + ; assignments (assignment_expression left: (assignable_expression) @variable) @@ -167,6 +190,7 @@ (const_builtin) (part_of_builtin) (rethrow_builtin) + (void_type) "abstract" "as" "async" diff --git a/test.dart b/test.dart index e69de29..aef5d8e 100644 --- a/test.dart +++ b/test.dart @@ -0,0 +1,26 @@ +class SomeClass { + final str = ''; + int get getter => 12; + void set setter(int value) {} + void method() => print('asdf'); +} + +String topLevelFn() => 'str'; + +extension SomeExtension on SomeClass { + void extensionMethod() => print('extension'); + } + +void main() { + final instance = SomeClass(); + instance.str; + instance.getter; + instance.setter = 12; + instance.method(); + topLevelFn(); + instance.extensionMethod(); + instance + ..method() + ..str + ..getter; +} \ No newline at end of file diff --git a/test/highlight/functions.dart b/test/highlight/functions.dart new file mode 100644 index 0000000..b5cd022 --- /dev/null +++ b/test/highlight/functions.dart @@ -0,0 +1,38 @@ +class SomeClass { + final str = ''; + int get getter => 12; + void set setter(int value) {} + void method() => print('asdf'); + // ^ function +} + +String topLevelFn() => 'str'; +// ^ function + +extension SomeExtension on SomeClass { + void extensionMethod() => print('extension'); + // ^ function +} + +void main() { + final instance = SomeClass(); + instance.str; + // ^ property + instance.getter; + // ^ property + instance.setter = 12; + // ^ property + instance.method(); + // ^ function + topLevelFn(); + // <- function + instance.extensionMethod(); + // ^ function + instance + ..method() + // ^ function + ..str + // ^ property + ..getter; + // ^ property +} \ No newline at end of file diff --git a/test/highlight/keywords.dart b/test/highlight/keywords.dart index 886b775..047ceb9 100644 --- a/test/highlight/keywords.dart +++ b/test/highlight/keywords.dart @@ -44,7 +44,7 @@ class Other extends Foo { final int b = 2; void foo(covariant String test) {} - // <- type + // <- keyword // ^ keyword factory Other.something() => Other(); // <- keyword @@ -121,7 +121,7 @@ void main() { } void foo() async { -// <- type +// <- keyword // ^ keyword await other(''); // <- keyword diff --git a/test/highlight/types.dart b/test/highlight/types.dart index da30f4d..4cd81d8 100644 --- a/test/highlight/types.dart +++ b/test/highlight/types.dart @@ -22,8 +22,7 @@ class Person { String getName() { // <- type - // ^ method - // The above used to be 'function.method', not 'method'. Fix it? + // ^ function return this.name; return Material.DENIM;