-
Notifications
You must be signed in to change notification settings - Fork 48
Fixed function highlighting #65
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
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 |
---|---|---|
|
@@ -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,13 +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) @function) | ||
(enum_declaration | ||
name: (identifier) @type) | ||
(enum_constant | ||
name: (identifier) @method) | ||
(type_identifier) @type | ||
(void_type) @type | ||
|
||
((scoped_identifier | ||
scope: (identifier) @type | ||
|
@@ -115,19 +125,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)) | ||
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. For now, I'm not worrying about annotating the differences between probably will look at this later, if it's considered beneficial |
||
(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) | ||
|
@@ -170,6 +197,7 @@ | |
(const_builtin) | ||
(part_of_builtin) | ||
(rethrow_builtin) | ||
(void_type) | ||
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. void is not really a type in dart, and most existing highlighting treats it as a keyword (thinking mostly the LSP syntax highlighting the vscode implements) |
||
"abstract" | ||
"as" | ||
"async" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
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.
This is the pattern both nvim and zed are utilizing to delineate between constructors and function calls