mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-06 05:20:00 -04:00
feat!: drop modules, general refactor and cleanup
This commit is contained in:
parent
c13e28f894
commit
2c8f2f2fad
829 changed files with 4905 additions and 8010 deletions
22
runtime/queries/ecma/folds.scm
Normal file
22
runtime/queries/ecma/folds.scm
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[
|
||||
(for_in_statement)
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(arrow_function)
|
||||
(function)
|
||||
(function_declaration)
|
||||
(class_declaration)
|
||||
(method_definition)
|
||||
(do_statement)
|
||||
(with_statement)
|
||||
(switch_statement)
|
||||
(switch_case)
|
||||
(switch_default)
|
||||
(import_statement)
|
||||
(if_statement)
|
||||
(try_statement)
|
||||
(catch_clause)
|
||||
(object)
|
||||
(generator_function)
|
||||
(generator_function_declaration)
|
||||
] @fold
|
||||
357
runtime/queries/ecma/highlights.scm
Normal file
357
runtime/queries/ecma/highlights.scm
Normal file
|
|
@ -0,0 +1,357 @@
|
|||
; Types
|
||||
|
||||
; Javascript
|
||||
|
||||
; Variables
|
||||
;-----------
|
||||
(identifier) @variable
|
||||
|
||||
; Properties
|
||||
;-----------
|
||||
|
||||
(property_identifier) @property
|
||||
(shorthand_property_identifier) @property
|
||||
(private_property_identifier) @property
|
||||
|
||||
(variable_declarator
|
||||
name: (object_pattern
|
||||
(shorthand_property_identifier_pattern))) @variable
|
||||
|
||||
; Special identifiers
|
||||
;--------------------
|
||||
|
||||
((identifier) @type
|
||||
(#lua-match? @type "^[A-Z]"))
|
||||
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
|
||||
|
||||
((shorthand_property_identifier) @constant
|
||||
(#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#any-of? @variable.builtin
|
||||
"arguments"
|
||||
"module"
|
||||
"console"
|
||||
"window"
|
||||
"document"))
|
||||
|
||||
((identifier) @type.builtin
|
||||
(#any-of? @type.builtin
|
||||
"Object"
|
||||
"Function"
|
||||
"Boolean"
|
||||
"Symbol"
|
||||
"Number"
|
||||
"Math"
|
||||
"Date"
|
||||
"String"
|
||||
"RegExp"
|
||||
"Map"
|
||||
"Set"
|
||||
"WeakMap"
|
||||
"WeakSet"
|
||||
"Promise"
|
||||
"Array"
|
||||
"Int8Array"
|
||||
"Uint8Array"
|
||||
"Uint8ClampedArray"
|
||||
"Int16Array"
|
||||
"Uint16Array"
|
||||
"Int32Array"
|
||||
"Uint32Array"
|
||||
"Float32Array"
|
||||
"Float64Array"
|
||||
"ArrayBuffer"
|
||||
"DataView"
|
||||
"Error"
|
||||
"EvalError"
|
||||
"InternalError"
|
||||
"RangeError"
|
||||
"ReferenceError"
|
||||
"SyntaxError"
|
||||
"TypeError"
|
||||
"URIError"))
|
||||
|
||||
((identifier) @namespace.builtin
|
||||
(#eq? @namespace.builtin "Intl"))
|
||||
|
||||
((identifier) @function.builtin
|
||||
(#any-of? @function.builtin
|
||||
"eval"
|
||||
"isFinite"
|
||||
"isNaN"
|
||||
"parseFloat"
|
||||
"parseInt"
|
||||
"decodeURI"
|
||||
"decodeURIComponent"
|
||||
"encodeURI"
|
||||
"encodeURIComponent"
|
||||
"require"))
|
||||
|
||||
; Function and method definitions
|
||||
;--------------------------------
|
||||
|
||||
(function
|
||||
name: (identifier) @function)
|
||||
(function_declaration
|
||||
name: (identifier) @function)
|
||||
(generator_function
|
||||
name: (identifier) @function)
|
||||
(generator_function_declaration
|
||||
name: (identifier) @function)
|
||||
(method_definition
|
||||
name: [(property_identifier) (private_property_identifier)] @method)
|
||||
(method_definition
|
||||
name: (property_identifier) @constructor
|
||||
(#eq? @constructor "constructor"))
|
||||
|
||||
(pair
|
||||
key: (property_identifier) @method
|
||||
value: (function))
|
||||
(pair
|
||||
key: (property_identifier) @method
|
||||
value: (arrow_function))
|
||||
|
||||
(assignment_expression
|
||||
left: (member_expression
|
||||
property: (property_identifier) @method)
|
||||
right: (arrow_function))
|
||||
(assignment_expression
|
||||
left: (member_expression
|
||||
property: (property_identifier) @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)
|
||||
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
property: [(property_identifier) (private_property_identifier)] @method.call))
|
||||
|
||||
; Constructor
|
||||
;------------
|
||||
|
||||
(new_expression
|
||||
constructor: (identifier) @constructor)
|
||||
|
||||
; Variables
|
||||
;----------
|
||||
(namespace_import
|
||||
(identifier) @namespace)
|
||||
|
||||
; Decorators
|
||||
;----------
|
||||
(decorator "@" @attribute (identifier) @attribute)
|
||||
(decorator "@" @attribute (call_expression (identifier) @attribute))
|
||||
|
||||
; Literals
|
||||
;---------
|
||||
|
||||
[
|
||||
(this)
|
||||
(super)
|
||||
] @variable.builtin
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#eq? @variable.builtin "self"))
|
||||
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
] @boolean
|
||||
|
||||
[
|
||||
(null)
|
||||
(undefined)
|
||||
] @constant.builtin
|
||||
|
||||
(comment) @comment @spell
|
||||
|
||||
((comment) @comment.documentation
|
||||
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
|
||||
|
||||
(hash_bang_line) @preproc
|
||||
|
||||
((string_fragment) @preproc
|
||||
(#eq? @preproc "use strict"))
|
||||
|
||||
(string) @string
|
||||
(template_string) @string
|
||||
(escape_sequence) @string.escape
|
||||
(regex_pattern) @string.regex
|
||||
(regex_flags) @character.special
|
||||
(regex "/" @punctuation.bracket) ; Regex delimiters
|
||||
|
||||
(number) @number
|
||||
((identifier) @number
|
||||
(#any-of? @number "NaN" "Infinity"))
|
||||
|
||||
; Punctuation
|
||||
;------------
|
||||
|
||||
";" @punctuation.delimiter
|
||||
"." @punctuation.delimiter
|
||||
"," @punctuation.delimiter
|
||||
|
||||
(pair ":" @punctuation.delimiter)
|
||||
(pair_pattern ":" @punctuation.delimiter)
|
||||
(switch_case ":" @punctuation.delimiter)
|
||||
(switch_default ":" @punctuation.delimiter)
|
||||
|
||||
[
|
||||
"--"
|
||||
"-"
|
||||
"-="
|
||||
"&&"
|
||||
"+"
|
||||
"++"
|
||||
"+="
|
||||
"&="
|
||||
"/="
|
||||
"**="
|
||||
"<<="
|
||||
"<"
|
||||
"<="
|
||||
"<<"
|
||||
"="
|
||||
"=="
|
||||
"==="
|
||||
"!="
|
||||
"!=="
|
||||
"=>"
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
"||"
|
||||
"%"
|
||||
"%="
|
||||
"*"
|
||||
"**"
|
||||
">>>"
|
||||
"&"
|
||||
"|"
|
||||
"^"
|
||||
"??"
|
||||
"*="
|
||||
">>="
|
||||
">>>="
|
||||
"^="
|
||||
"|="
|
||||
"&&="
|
||||
"||="
|
||||
"??="
|
||||
"..."
|
||||
] @operator
|
||||
|
||||
(binary_expression "/" @operator)
|
||||
(ternary_expression ["?" ":"] @conditional.ternary)
|
||||
(unary_expression ["!" "~" "-" "+"] @operator)
|
||||
(unary_expression ["delete" "void"] @keyword.operator)
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
((template_substitution ["${" "}"] @punctuation.special) @none)
|
||||
|
||||
; Keywords
|
||||
;----------
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"switch"
|
||||
"case"
|
||||
] @conditional
|
||||
|
||||
[
|
||||
"import"
|
||||
"from"
|
||||
] @include
|
||||
|
||||
(export_specifier "as" @include)
|
||||
(import_specifier "as" @include)
|
||||
(namespace_export "as" @include)
|
||||
(namespace_import "as" @include)
|
||||
|
||||
[
|
||||
"for"
|
||||
"of"
|
||||
"do"
|
||||
"while"
|
||||
"continue"
|
||||
] @repeat
|
||||
|
||||
[
|
||||
"break"
|
||||
"class"
|
||||
"const"
|
||||
"debugger"
|
||||
"export"
|
||||
"extends"
|
||||
"get"
|
||||
"let"
|
||||
"set"
|
||||
"static"
|
||||
"target"
|
||||
"var"
|
||||
"with"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"async"
|
||||
"await"
|
||||
] @keyword.coroutine
|
||||
|
||||
[
|
||||
"return"
|
||||
"yield"
|
||||
] @keyword.return
|
||||
|
||||
[
|
||||
"function"
|
||||
] @keyword.function
|
||||
|
||||
[
|
||||
"new"
|
||||
"delete"
|
||||
"in"
|
||||
"instanceof"
|
||||
"typeof"
|
||||
] @keyword.operator
|
||||
|
||||
[
|
||||
"throw"
|
||||
"try"
|
||||
"catch"
|
||||
"finally"
|
||||
] @exception
|
||||
|
||||
(export_statement
|
||||
"default" @keyword)
|
||||
(switch_default
|
||||
"default" @conditional)
|
||||
57
runtime/queries/ecma/indents.scm
Normal file
57
runtime/queries/ecma/indents.scm
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
[
|
||||
(arguments)
|
||||
(array)
|
||||
(binary_expression)
|
||||
(class_body)
|
||||
(export_clause)
|
||||
(formal_parameters)
|
||||
(named_imports)
|
||||
(object)
|
||||
(object_pattern)
|
||||
(parenthesized_expression)
|
||||
(return_statement)
|
||||
(statement_block)
|
||||
(switch_case)
|
||||
(switch_default)
|
||||
(switch_statement)
|
||||
(template_substitution)
|
||||
(ternary_expression)
|
||||
] @indent.begin
|
||||
|
||||
(arguments (call_expression) @indent.begin)
|
||||
(binary_expression (call_expression) @indent.begin)
|
||||
(expression_statement (call_expression) @indent.begin)
|
||||
(arrow_function
|
||||
body: (_) @_body
|
||||
(#not-has-type? @_body statement_block)
|
||||
) @indent.begin
|
||||
(assignment_expression
|
||||
right: (_) @_right
|
||||
(#not-has-type? @_right arrow_function function)
|
||||
) @indent.begin
|
||||
(variable_declarator
|
||||
value: (_) @_value
|
||||
(#not-has-type? @_value arrow_function call_expression function)
|
||||
) @indent.begin
|
||||
|
||||
(arguments ")" @indent.end)
|
||||
(object "}" @indent.end)
|
||||
(statement_block "}" @indent.end)
|
||||
|
||||
[
|
||||
(arguments (object))
|
||||
")"
|
||||
"}"
|
||||
"]"
|
||||
] @indent.branch
|
||||
(statement_block "{" @indent.branch)
|
||||
|
||||
(parenthesized_expression ("(" (_) ")" @indent.end))
|
||||
["}" "]"] @indent.end
|
||||
|
||||
(template_string) @indent.ignore
|
||||
|
||||
[
|
||||
(comment)
|
||||
(ERROR)
|
||||
] @indent.auto
|
||||
121
runtime/queries/ecma/injections.scm
Normal file
121
runtime/queries/ecma/injections.scm
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
(((comment) @_jsdoc_comment
|
||||
(#lua-match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content
|
||||
(#set! injection.language "jsdoc"))
|
||||
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
; html(`...`), html`...`, sql(...) etc
|
||||
(call_expression
|
||||
function: ((identifier) @injection.language)
|
||||
arguments: [
|
||||
(arguments
|
||||
(template_string) @injection.content)
|
||||
(template_string) @injection.content
|
||||
]
|
||||
(#lua-match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$")
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#not-eq? @injection.language "svg"))
|
||||
|
||||
; svg`...` or svg(`...`), which uses the html parser, so is not included in the previous query
|
||||
(call_expression
|
||||
function: ((identifier) @_name (#eq? @_name "svg"))
|
||||
arguments: [
|
||||
(arguments
|
||||
(template_string) @injection.content)
|
||||
(template_string) @injection.content
|
||||
]
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "html"))
|
||||
|
||||
|
||||
(call_expression
|
||||
function: ((identifier) @_name
|
||||
(#eq? @_name "gql"))
|
||||
arguments: ((template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "graphql")))
|
||||
|
||||
(call_expression
|
||||
function: ((identifier) @_name
|
||||
(#eq? @_name "hbs"))
|
||||
arguments: ((template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "glimmer")))
|
||||
|
||||
((glimmer_template) @injection.content
|
||||
(#set! injection.language "glimmer"))
|
||||
|
||||
; styled.div`<css>`
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
object: (identifier) @_name
|
||||
(#eq? @_name "styled"))
|
||||
arguments: ((template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "css")))
|
||||
|
||||
; styled(Component)`<css>`
|
||||
(call_expression
|
||||
function: (call_expression
|
||||
function: (identifier) @_name
|
||||
(#eq? @_name "styled"))
|
||||
arguments: ((template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "css")))
|
||||
|
||||
; styled.div.attrs({ prop: "foo" })`<css>`
|
||||
(call_expression
|
||||
function: (call_expression
|
||||
function: (member_expression
|
||||
object: (member_expression
|
||||
object: (identifier) @_name
|
||||
(#eq? @_name "styled"))))
|
||||
arguments: ((template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "css")))
|
||||
|
||||
|
||||
; styled(Component).attrs({ prop: "foo" })`<css>`
|
||||
(call_expression
|
||||
function: (call_expression
|
||||
function: (member_expression
|
||||
object: (call_expression
|
||||
function: (identifier) @_name
|
||||
(#eq? @_name "styled"))))
|
||||
arguments: ((template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "css")))
|
||||
|
||||
((regex_pattern) @injection.content
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
; ((comment) @_gql_comment
|
||||
; (#eq? @_gql_comment "/* GraphQL */")
|
||||
; (template_string) @injection.content
|
||||
; (#set! injection.language "graphql"))
|
||||
|
||||
((template_string) @injection.content
|
||||
(#lua-match? @injection.content "^`#graphql")
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "graphql"))
|
||||
|
||||
; el.innerHTML = `<html>`
|
||||
(assignment_expression
|
||||
left:
|
||||
(member_expression
|
||||
property: (property_identifier) @_prop
|
||||
(#any-of? @_prop "outerHTML" "innerHTML"))
|
||||
right: (template_string) @injection.content
|
||||
(#offset! @injection.content 0 1 0 -1)
|
||||
(#set! injection.language "html"))
|
||||
|
||||
; el.innerHTML = '<html>'
|
||||
(assignment_expression
|
||||
left:
|
||||
(member_expression
|
||||
property: (property_identifier) @_prop
|
||||
(#any-of? @_prop "outerHTML" "innerHTML"))
|
||||
right:
|
||||
(string (string_fragment) @injection.content)
|
||||
(#set! injection.language "html"))
|
||||
37
runtime/queries/ecma/locals.scm
Normal file
37
runtime/queries/ecma/locals.scm
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
; Scopes
|
||||
;-------
|
||||
|
||||
(statement_block) @scope
|
||||
(function) @scope
|
||||
(arrow_function) @scope
|
||||
(function_declaration) @scope
|
||||
(method_definition) @scope
|
||||
(for_statement) @scope
|
||||
(for_in_statement) @scope
|
||||
(catch_clause) @scope
|
||||
|
||||
; Definitions
|
||||
;------------
|
||||
|
||||
(variable_declarator
|
||||
name: (identifier) @definition.var)
|
||||
|
||||
(import_specifier
|
||||
(identifier) @definition.import)
|
||||
|
||||
(namespace_import
|
||||
(identifier) @definition.import)
|
||||
|
||||
(function_declaration
|
||||
((identifier) @definition.function)
|
||||
(#set! definition.var.scope parent))
|
||||
|
||||
(method_definition
|
||||
((property_identifier) @definition.function)
|
||||
(#set! definition.var.scope parent))
|
||||
|
||||
; References
|
||||
;------------
|
||||
|
||||
(identifier) @reference
|
||||
(shorthand_property_identifier) @reference
|
||||
Loading…
Add table
Add a link
Reference in a new issue