mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Merge pull request #79 from steelsojka/feat/typescript-queries
feat(queries): add typescript and javascript queries
This commit is contained in:
commit
dd7e67ddb4
5 changed files with 256 additions and 2 deletions
|
|
@ -159,8 +159,8 @@ List of currently supported languages:
|
|||
- [x] cpp (maintained by @theHamsta, extends C queries)
|
||||
- [ ] rust
|
||||
- [x] python (maintained by @theHamsta)
|
||||
- [ ] javascript
|
||||
- [ ] typescript
|
||||
- [x] javascript (maintained by @steelsojka)
|
||||
- [x] typescript (maintained by @steelsojka)
|
||||
- [ ] tsx
|
||||
- [ ] json
|
||||
- [x] html (maintained by @TravonteD)
|
||||
|
|
|
|||
190
queries/javascript/highlights.scm
Normal file
190
queries/javascript/highlights.scm
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
; Types
|
||||
|
||||
; Javascript
|
||||
; Special identifiers
|
||||
;--------------------
|
||||
|
||||
((identifier) @constant
|
||||
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
|
||||
|
||||
((shorthand_property_identifier) @constant
|
||||
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
|
||||
|
||||
((identifier) @constructor
|
||||
(#match? @constructor "^[A-Z]"))
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#match? @variable.builtin "^(arguments|module|console|window|document)$"))
|
||||
|
||||
((identifier) @function.builtin
|
||||
(#eq? @function.builtin "require"))
|
||||
|
||||
; Function and method definitions
|
||||
;--------------------------------
|
||||
|
||||
(function
|
||||
name: (identifier) @function)
|
||||
(function_declaration
|
||||
name: (identifier) @function)
|
||||
(method_definition
|
||||
name: (property_identifier) @function.method)
|
||||
|
||||
(pair
|
||||
key: (property_identifier) @function.method
|
||||
value: (function))
|
||||
(pair
|
||||
key: (property_identifier) @function.method
|
||||
value: (arrow_function))
|
||||
|
||||
(assignment_expression
|
||||
left: (member_expression
|
||||
property: (property_identifier) @function.method)
|
||||
right: (arrow_function))
|
||||
(assignment_expression
|
||||
left: (member_expression
|
||||
property: (property_identifier) @function.method)
|
||||
right: (function))
|
||||
|
||||
(variable_declarator
|
||||
name: (identifier) @function
|
||||
value: (arrow_function))
|
||||
(variable_declarator
|
||||
name: (identifier) @function
|
||||
value: (function))
|
||||
|
||||
(assignment_expression
|
||||
left: (identifier) @function
|
||||
right: (arrow_function))
|
||||
(assignment_expression
|
||||
left: (identifier) @function
|
||||
right: (function))
|
||||
|
||||
; Function and method calls
|
||||
;--------------------------
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
property: (property_identifier) @function.method))
|
||||
|
||||
; Variables
|
||||
;----------
|
||||
|
||||
(formal_parameters (identifier) @variable.parameter)
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
; Properties
|
||||
;-----------
|
||||
|
||||
(property_identifier) @property
|
||||
|
||||
; Literals
|
||||
;---------
|
||||
|
||||
(this) @variable.builtin
|
||||
(super) @variable.builtin
|
||||
|
||||
(true) @constant.builtin
|
||||
(false) @constant.builtin
|
||||
(null) @constant.builtin
|
||||
(comment) @comment
|
||||
(string) @string
|
||||
(regex) @string.special
|
||||
(template_string) @string
|
||||
(number) @number
|
||||
|
||||
; Punctuation
|
||||
;------------
|
||||
|
||||
(template_substitution
|
||||
"${" @punctuation.special
|
||||
"}" @punctuation.special) @embedded
|
||||
|
||||
";" @punctuation.delimiter
|
||||
"." @punctuation.delimiter
|
||||
"," @punctuation.delimiter
|
||||
|
||||
"--" @operator
|
||||
"-" @operator
|
||||
"-=" @operator
|
||||
"&&" @operator
|
||||
"+" @operator
|
||||
"++" @operator
|
||||
"+=" @operator
|
||||
"<" @operator
|
||||
"<<" @operator
|
||||
"=" @operator
|
||||
"==" @operator
|
||||
"===" @operator
|
||||
"=>" @operator
|
||||
">" @operator
|
||||
">>" @operator
|
||||
"||" @operator
|
||||
"??" @operator
|
||||
|
||||
"(" @punctuation.bracket
|
||||
")" @punctuation.bracket
|
||||
"[" @punctuation.bracket
|
||||
"]" @punctuation.bracket
|
||||
"{" @punctuation.bracket
|
||||
"}" @punctuation.bracket
|
||||
|
||||
; Keywords
|
||||
;----------
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"switch"
|
||||
"case"
|
||||
"default"
|
||||
] @conditional
|
||||
|
||||
[
|
||||
"import"
|
||||
"from"
|
||||
"as"
|
||||
] @include
|
||||
|
||||
[
|
||||
"for"
|
||||
"of"
|
||||
"do"
|
||||
"while"
|
||||
"continue"
|
||||
] @repeat
|
||||
|
||||
[
|
||||
"async"
|
||||
"await"
|
||||
"break"
|
||||
"catch"
|
||||
"class"
|
||||
"const"
|
||||
"debugger"
|
||||
"delete"
|
||||
"export"
|
||||
"extends"
|
||||
"finally"
|
||||
"function"
|
||||
"get"
|
||||
"in"
|
||||
"instanceof"
|
||||
"let"
|
||||
"new"
|
||||
"return"
|
||||
"set"
|
||||
"static"
|
||||
"switch"
|
||||
"target"
|
||||
"throw"
|
||||
"try"
|
||||
"typeof"
|
||||
"var"
|
||||
"void"
|
||||
"with"
|
||||
"yield"
|
||||
] @keyword
|
||||
35
queries/javascript/locals.scm
Normal file
35
queries/javascript/locals.scm
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
; Scopes
|
||||
;-------
|
||||
|
||||
(statement_block) @scope
|
||||
(function) @scope
|
||||
(arrow_function) @scope
|
||||
(function_declaration) @scope
|
||||
(method_definition) @scope
|
||||
|
||||
; Definitions
|
||||
;------------
|
||||
|
||||
(formal_parameters
|
||||
(identifier) @definition)
|
||||
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(identifier) @definition))
|
||||
|
||||
(formal_parameters
|
||||
(object_pattern
|
||||
(shorthand_property_identifier) @definition))
|
||||
|
||||
(formal_parameters
|
||||
(array_pattern
|
||||
(identifier) @definition))
|
||||
|
||||
(variable_declarator
|
||||
name: (identifier) @definition)
|
||||
|
||||
; References
|
||||
;------------
|
||||
|
||||
(identifier) @reference
|
||||
|
||||
27
queries/typescript/highlights.scm
Normal file
27
queries/typescript/highlights.scm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[
|
||||
"abstract"
|
||||
"declare"
|
||||
"enum"
|
||||
"export"
|
||||
"implements"
|
||||
"interface"
|
||||
"keyof"
|
||||
"namespace"
|
||||
"private"
|
||||
"protected"
|
||||
"public"
|
||||
"type"
|
||||
] @keyword
|
||||
|
||||
(readonly) @keyword
|
||||
(type_identifier) @type
|
||||
(predefined_type) @type.builtin
|
||||
|
||||
(type_arguments
|
||||
"<" @punctuation.bracket
|
||||
">" @punctuation.bracket)
|
||||
|
||||
; Variables
|
||||
|
||||
(required_parameter (identifier) @variable.parameter)
|
||||
(optional_parameter (identifier) @variable.parameter)
|
||||
2
queries/typescript/locals.scm
Normal file
2
queries/typescript/locals.scm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(required_parameter (identifier) @definition)
|
||||
(optional_parameter (identifier) @definition)
|
||||
Loading…
Add table
Add a link
Reference in a new issue