forked from helix-editor/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor queries for ecma based languages (helix-editor#7207)
- Loading branch information
1 parent
267f088
commit 1039a22
Showing
38 changed files
with
492 additions
and
305 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
; Function and method parameters | ||
;------------------------------- | ||
|
||
; Javascript and Typescript Treesitter grammars deviate when defining the | ||
; tree structure for parameters, so we need to address them in each specific | ||
; language instead of ecma. | ||
|
||
; (p) | ||
(formal_parameters | ||
(identifier) @variable.parameter) | ||
|
||
; (...p) | ||
(formal_parameters | ||
(rest_pattern | ||
(identifier) @variable.parameter)) | ||
|
||
; ({ p }) | ||
(formal_parameters | ||
(object_pattern | ||
(shorthand_property_identifier_pattern) @variable.parameter)) | ||
|
||
; ({ a: p }) | ||
(formal_parameters | ||
(object_pattern | ||
(pair_pattern | ||
value: (identifier) @variable.parameter))) | ||
|
||
; ([ p ]) | ||
(formal_parameters | ||
(array_pattern | ||
(identifier) @variable.parameter)) | ||
|
||
; (p = 1) | ||
(formal_parameters | ||
(assignment_pattern | ||
left: (identifier) @variable.parameter)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; Definitions | ||
;------------ | ||
; Javascript and Typescript Treesitter grammars deviate when defining the | ||
; tree structure for parameters, so we need to address them in each specific | ||
; language instead of ecma. | ||
|
||
; (i) | ||
(formal_parameters | ||
(identifier) @local.definition) | ||
|
||
; (i = 1) | ||
(formal_parameters | ||
(assignment_pattern | ||
left: (identifier) @local.definition)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
( | ||
(comment)* @doc | ||
. | ||
(method_definition | ||
name: (property_identifier) @name) @definition.method | ||
(#not-eq? @name "constructor") | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.method) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
[ | ||
(class | ||
name: (_) @name) | ||
(class_declaration | ||
name: (_) @name) | ||
] @definition.class | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.class) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
[ | ||
(function | ||
name: (identifier) @name) | ||
(function_declaration | ||
name: (identifier) @name) | ||
(generator_function | ||
name: (identifier) @name) | ||
(generator_function_declaration | ||
name: (identifier) @name) | ||
] @definition.function | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.function) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
(lexical_declaration | ||
(variable_declarator | ||
name: (identifier) @name | ||
value: [(arrow_function) (function)]) @definition.function) | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.function) | ||
) | ||
|
||
( | ||
(comment)* @doc | ||
. | ||
(variable_declaration | ||
(variable_declarator | ||
name: (identifier) @name | ||
value: [(arrow_function) (function)]) @definition.function) | ||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$") | ||
(#select-adjacent! @doc @definition.function) | ||
) | ||
|
||
(assignment_expression | ||
left: [ | ||
(identifier) @name | ||
(member_expression | ||
property: (property_identifier) @name) | ||
] | ||
right: [(arrow_function) (function)] | ||
) @definition.function | ||
|
||
(pair | ||
key: (property_identifier) @name | ||
value: [(arrow_function) (function)]) @definition.function | ||
|
||
( | ||
(call_expression | ||
function: (identifier) @name) @reference.call | ||
(#not-match? @name "^(require)$") | ||
) | ||
|
||
(call_expression | ||
function: (member_expression | ||
property: (property_identifier) @name) | ||
arguments: (_) @reference.call) | ||
|
||
(new_expression | ||
constructor: (_) @name) @reference.class |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
; Opening elements | ||
; ---------------- | ||
|
||
(jsx_opening_element ((identifier) @constructor | ||
(#match? @constructor "^[A-Z]"))) | ||
|
||
; Handle the dot operator effectively - <My.Component> | ||
(jsx_opening_element ((nested_identifier (identifier) @tag (identifier) @constructor))) | ||
|
||
(jsx_opening_element (identifier) @tag) | ||
|
||
; Closing elements | ||
; ---------------- | ||
|
||
(jsx_closing_element ((identifier) @constructor | ||
(#match? @constructor "^[A-Z]"))) | ||
|
||
; Handle the dot operator effectively - </My.Component> | ||
(jsx_closing_element ((nested_identifier (identifier) @tag (identifier) @constructor))) | ||
|
||
(jsx_closing_element (identifier) @tag) | ||
|
||
; Self-closing elements | ||
; --------------------- | ||
|
||
(jsx_self_closing_element ((identifier) @constructor | ||
(#match? @constructor "^[A-Z]"))) | ||
|
||
; Handle the dot operator effectively - <My.Component /> | ||
(jsx_self_closing_element ((nested_identifier (identifier) @tag (identifier) @constructor))) | ||
|
||
(jsx_self_closing_element (identifier) @tag) | ||
|
||
; Attributes | ||
; ---------- | ||
|
||
(jsx_attribute (property_identifier) @variable.other.member) | ||
|
||
; Punctuation | ||
; ----------- | ||
|
||
; Handle attribute delimiter | ||
(jsx_attribute "=" @punctuation.delimiter) | ||
|
||
; <Component> | ||
(jsx_opening_element ["<" ">"] @punctuation.bracket) | ||
|
||
; </Component> | ||
(jsx_closing_element ["<" "/" ">"] @punctuation.bracket) | ||
|
||
; <Component /> | ||
(jsx_self_closing_element ["<" "/" ">"] @punctuation.bracket) | ||
|
||
; <> ... </> | ||
(jsx_fragment ["<" "/" ">"] @punctuation.bracket) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
(jsx_fragment) | ||
(jsx_element) | ||
(jsx_self_closing_element) | ||
] @indent | ||
|
||
(parenthesized_expression) @indent |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
; Namespaces | ||
; ---------- | ||
|
||
(internal_module | ||
[((identifier) @namespace) ((nested_identifier (identifier) @namespace))]) | ||
|
||
(ambient_declaration "global" @namespace) | ||
|
||
; Parameters | ||
; ---------- | ||
; Javascript and Typescript Treesitter grammars deviate when defining the | ||
; tree structure for parameters, so we need to address them in each specific | ||
; language instead of ecma. | ||
|
||
; (p: t) | ||
; (p: t = 1) | ||
(required_parameter | ||
(identifier) @variable.parameter) | ||
|
||
; (...p: t) | ||
(required_parameter | ||
(rest_pattern | ||
(identifier) @variable.parameter)) | ||
|
||
; ({ p }: { p: t }) | ||
(required_parameter | ||
(object_pattern | ||
(shorthand_property_identifier_pattern) @variable.parameter)) | ||
|
||
; ({ a: p }: { a: t }) | ||
(required_parameter | ||
(object_pattern | ||
(pair_pattern | ||
value: (identifier) @variable.parameter))) | ||
|
||
; ([ p ]: t[]) | ||
(required_parameter | ||
(array_pattern | ||
(identifier) @variable.parameter)) | ||
|
||
; (p?: t) | ||
; (p?: t = 1) // Invalid but still posible to hihglight. | ||
(optional_parameter | ||
(identifier) @variable.parameter) | ||
|
||
; (...p?: t) // Invalid but still posible to hihglight. | ||
(optional_parameter | ||
(rest_pattern | ||
(identifier) @variable.parameter)) | ||
|
||
; ({ p }: { p?: t}) | ||
(optional_parameter | ||
(object_pattern | ||
(shorthand_property_identifier_pattern) @variable.parameter)) | ||
|
||
; ({ a: p }: { a?: t }) | ||
(optional_parameter | ||
(object_pattern | ||
(pair_pattern | ||
value: (identifier) @variable.parameter))) | ||
|
||
; ([ p ]?: t[]) // Invalid but still posible to hihglight. | ||
(optional_parameter | ||
(array_pattern | ||
(identifier) @variable.parameter)) | ||
|
||
; Punctuation | ||
; ----------- | ||
|
||
[ | ||
":" | ||
] @punctuation.delimiter | ||
|
||
(optional_parameter "?" @punctuation.special) | ||
(property_signature "?" @punctuation.special) | ||
|
||
(conditional_type ["?" ":"] @operator) | ||
|
||
; Keywords | ||
; -------- | ||
|
||
[ | ||
"abstract" | ||
"declare" | ||
"export" | ||
"infer" | ||
"implements" | ||
"keyof" | ||
"namespace" | ||
"override" | ||
] @keyword | ||
|
||
[ | ||
"type" | ||
"interface" | ||
"enum" | ||
] @keyword.storage.type | ||
|
||
[ | ||
"public" | ||
"private" | ||
"protected" | ||
"readonly" | ||
] @keyword.storage.modifier | ||
|
||
; Types | ||
; ----- | ||
|
||
(type_identifier) @type | ||
(predefined_type) @type.builtin | ||
|
||
; Type arguments and parameters | ||
; ----------------------------- | ||
|
||
(type_arguments | ||
[ | ||
"<" | ||
">" | ||
] @punctuation.bracket) | ||
|
||
(type_parameters | ||
[ | ||
"<" | ||
">" | ||
] @punctuation.bracket) | ||
|
||
; Literals | ||
; -------- | ||
|
||
[ | ||
(template_literal_type) | ||
] @string | ||
|
||
; Tokens | ||
; ------ | ||
|
||
(template_type | ||
"${" @punctuation.special | ||
"}" @punctuation.special) @embedded |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
(enum_declaration) | ||
(interface_declaration) | ||
(object_type) | ||
] @indent |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
; Definitions | ||
;------------ | ||
|
||
; Javascript and Typescript Treesitter grammars deviate when defining the | ||
; tree structure for parameters, so we need to address them in each specific | ||
; language instead of ecma. | ||
|
||
; (i: t) | ||
; (i: t = 1) | ||
(required_parameter | ||
(identifier) @local.definition) | ||
|
||
; (i?: t) | ||
; (i?: t = 1) // Invalid but still posible to hihglight. | ||
(optional_parameter | ||
(identifier) @local.definition) |
Oops, something went wrong.