Skip to content

Commit 1aef5a6

Browse files
authored
Merge pull request #65 from matthewnitschke/fixed_function_highlighting
Fixed function highlighting
2 parents adf31d8 + ceedf12 commit 1aef5a6

File tree

4 files changed

+79
-14
lines changed

4 files changed

+79
-14
lines changed

queries/highlights.scm

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
; Methods
44
; --------------------
5-
;; TODO: does not work
6-
;(function_type
7-
;name: (identifier) @method)
85
(super) @function
96

7+
; TODO: add method/call_expression to grammar and
8+
; distinguish method call from variable access
9+
(function_expression_body
10+
(identifier) @function)
11+
12+
; NOTE: This query is a bit of a work around for the fact that the dart grammar doesn't
13+
; specifically identify a node as a function call
14+
(((identifier) @function (#match? @function "^_?[a-z]"))
15+
. (selector . (argument_part))) @function
16+
1017
; Annotations
1118
; --------------------
1219
(annotation
@@ -87,13 +94,16 @@
8794
(scoped_identifier
8895
scope: (identifier) @type)
8996
(function_signature
90-
name: (identifier) @method)
97+
name: (identifier) @function)
9198
(getter_signature
92-
(identifier) @method)
99+
(identifier) @function)
93100
(setter_signature
101+
name: (identifier) @function)
102+
(enum_declaration
103+
name: (identifier) @type)
104+
(enum_constant
94105
name: (identifier) @method)
95106
(type_identifier) @type
96-
(void_type) @type
97107

98108
((scoped_identifier
99109
scope: (identifier) @type
@@ -115,19 +125,36 @@
115125
(inferred_type) @keyword
116126

117127
((identifier) @type
118-
(#match? @type "^_?[A-Z]"))
128+
(#match? @type "^_?[A-Z].*[a-z]"))
119129

120130
("Function" @type)
121-
(void_type) @type
122131

123132
(this) @variable.builtin
124133

125134
; properties
126-
; TODO: add method/call_expression to grammar and
127-
; distinguish method call from variable access
135+
(expression_statement
136+
(selector
137+
(unconditional_assignable_selector
138+
(identifier) @function))
139+
(selector (argument_part (arguments)))
140+
)
141+
(expression_statement
142+
(cascade_section
143+
(cascade_selector (identifier) @function)
144+
(argument_part (arguments))
145+
)
146+
)
147+
128148
(unconditional_assignable_selector
129149
(identifier) @property)
130150

151+
(conditional_assignable_selector
152+
(identifier) @property)
153+
154+
(cascade_section
155+
(cascade_selector
156+
(identifier) @property))
157+
131158
; assignments
132159
(assignment_expression
133160
left: (assignable_expression) @variable)
@@ -170,6 +197,7 @@
170197
(const_builtin)
171198
(part_of_builtin)
172199
(rethrow_builtin)
200+
(void_type)
173201
"abstract"
174202
"as"
175203
"async"

test/highlight/functions.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class SomeClass {
2+
final str = '';
3+
int get getter => 12;
4+
void set setter(int value) {}
5+
void method() => print('asdf');
6+
// ^ function
7+
}
8+
9+
String topLevelFn() => 'str';
10+
// ^ function
11+
12+
extension SomeExtension on SomeClass {
13+
void extensionMethod() => print('extension');
14+
// ^ function
15+
}
16+
17+
void main() {
18+
final instance = SomeClass();
19+
instance.str;
20+
// ^ property
21+
instance.getter;
22+
// ^ property
23+
instance.setter = 12;
24+
// ^ property
25+
instance.method();
26+
// ^ function
27+
topLevelFn();
28+
// <- function
29+
instance.extensionMethod();
30+
// ^ function
31+
instance
32+
..method()
33+
// ^ function
34+
..str
35+
// ^ property
36+
..getter;
37+
// ^ property
38+
}

test/highlight/keywords.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Other extends Foo {
4444
final int b = 2;
4545

4646
void foo(covariant String test) {}
47-
// <- type
47+
// <- keyword
4848
// ^ keyword
4949
factory Other.something() => Other();
5050
// <- keyword
@@ -121,7 +121,7 @@ void main() {
121121
}
122122

123123
void foo() async {
124-
// <- type
124+
// <- keyword
125125
// ^ keyword
126126
await other('');
127127
// <- keyword

test/highlight/types.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class Person {
2323

2424
String getName() {
2525
// <- type
26-
// ^ method
27-
// The above used to be 'function.method', not 'method'. Fix it?
26+
// ^ function
2827
return this.name;
2928

3029
return Material.DENIM;

0 commit comments

Comments
 (0)