feat(treesitter): replace nvim-treesitter with pack-managed parsers

This commit is contained in:
2026-04-12 11:46:54 +02:00
parent ec81afbab7
commit cf898d1fee
107 changed files with 8555 additions and 13 deletions
+27
View File
@@ -0,0 +1,27 @@
; SPDX-License-Identifier: Apache-2.0
; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter)
[
(arguments)
(for_in_statement)
(for_statement)
(while_statement)
(arrow_function)
(function_expression)
(function_declaration)
(class_declaration)
(method_definition)
(do_statement)
(with_statement)
(switch_statement)
(switch_case)
(switch_default)
(import_statement)+
(if_statement)
(try_statement)
(catch_clause)
(array)
(object)
(generator_function)
(generator_function_declaration)
] @fold
+395
View File
@@ -0,0 +1,395 @@
; SPDX-License-Identifier: Apache-2.0
; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter)
; Types
; Javascript
; Variables
;-----------
(identifier) @variable
; Properties
;-----------
(property_identifier) @variable.member
(shorthand_property_identifier) @variable.member
(private_property_identifier) @variable.member
(object_pattern
(shorthand_property_identifier_pattern) @variable)
(object_pattern
(object_assignment_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"))
(statement_identifier) @label
; Function and method definitions
;--------------------------------
(function_expression
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)
] @function.method)
(method_definition
name: (property_identifier) @constructor
(#eq? @constructor "constructor"))
(pair
key: (property_identifier) @function.method
value: (function_expression))
(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_expression))
(variable_declarator
name: (identifier) @function
value: (arrow_function))
(variable_declarator
name: (identifier) @function
value: (function_expression))
(assignment_expression
left: (identifier) @function
right: (arrow_function))
(assignment_expression
left: (identifier) @function
right: (function_expression))
; Function and method calls
;--------------------------
(call_expression
function: (identifier) @function.call)
(call_expression
function: (member_expression
property: [
(property_identifier)
(private_property_identifier)
] @function.method.call))
(call_expression
function: (await_expression
(identifier) @function.call))
(call_expression
function: (await_expression
(member_expression
property: [
(property_identifier)
(private_property_identifier)
] @function.method.call)))
; Builtins
;---------
((identifier) @module.builtin
(#eq? @module.builtin "Intl"))
((identifier) @function.builtin
(#any-of? @function.builtin
"eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI"
"encodeURIComponent" "require"))
; Constructor
;------------
(new_expression
constructor: (identifier) @constructor)
; Decorators
;----------
(decorator
"@" @attribute
(identifier) @attribute)
(decorator
"@" @attribute
(call_expression
(identifier) @attribute))
(decorator
"@" @attribute
(member_expression
(property_identifier) @attribute))
(decorator
"@" @attribute
(call_expression
(member_expression
(property_identifier) @attribute)))
; Literals
;---------
[
(this)
(super)
] @variable.builtin
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))
[
(true)
(false)
] @boolean
[
(null)
(undefined)
] @constant.builtin
[
(comment)
(html_comment)
] @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
(hash_bang_line) @keyword.directive
((string_fragment) @keyword.directive
(#eq? @keyword.directive "use strict"))
(string) @string
(template_string) @string
(escape_sequence) @string.escape
(regex_pattern) @string.regexp
(regex_flags) @character.special
(regex
"/" @punctuation.bracket) ; Regex delimiters
(number) @number
((identifier) @number
(#any-of? @number "NaN" "Infinity"))
; Punctuation
;------------
[
";"
"."
","
":"
] @punctuation.delimiter
[
"--"
"-"
"-="
"&&"
"+"
"++"
"+="
"&="
"/="
"**="
"<<="
"<"
"<="
"<<"
"="
"=="
"==="
"!="
"!=="
"=>"
">"
">="
">>"
"||"
"%"
"%="
"*"
"**"
">>>"
"&"
"|"
"^"
"??"
"*="
">>="
">>>="
"^="
"|="
"&&="
"||="
"??="
"..."
] @operator
(binary_expression
"/" @operator)
(ternary_expression
[
"?"
":"
] @keyword.conditional.ternary)
(unary_expression
[
"!"
"~"
"-"
"+"
] @operator)
(unary_expression
[
"delete"
"void"
] @keyword.operator)
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(template_substitution
[
"${"
"}"
] @punctuation.special) @none
; Imports
;----------
(namespace_import
"*" @character.special
(identifier) @module)
(namespace_export
"*" @character.special
(identifier) @module)
(export_statement
"*" @character.special)
; Keywords
;----------
[
"if"
"else"
"switch"
"case"
] @keyword.conditional
[
"import"
"from"
"as"
"export"
] @keyword.import
[
"for"
"of"
"do"
"while"
"continue"
] @keyword.repeat
[
"break"
"const"
"debugger"
"extends"
"get"
"let"
"set"
"static"
"target"
"var"
"with"
] @keyword
"class" @keyword.type
[
"async"
"await"
] @keyword.coroutine
[
"return"
"yield"
] @keyword.return
"function" @keyword.function
[
"new"
"delete"
"in"
"instanceof"
"typeof"
] @keyword.operator
[
"throw"
"try"
"catch"
"finally"
] @keyword.exception
(export_statement
"default" @keyword)
(switch_default
"default" @keyword.conditional)
+85
View File
@@ -0,0 +1,85 @@
; SPDX-License-Identifier: Apache-2.0
; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter)
[
(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-kind-eq? @_body "statement_block")) @indent.begin
(assignment_expression
right: (_) @_right
(#not-kind-eq? @_right "arrow_function")) @indent.begin
(variable_declarator
value: (_) @_value
(#not-kind-eq? @_value "arrow_function" "call_expression")) @indent.begin
(arguments
")" @indent.end)
(object
"}" @indent.end)
(statement_block
"}" @indent.end)
[
(arguments
(object))
")"
"}"
"]"
] @indent.branch
(statement_block
"{" @indent.branch)
((parenthesized_expression
"("
(_)
")" @indent.end) @_outer
(#not-has-parent? @_outer if_statement))
[
"}"
"]"
] @indent.end
(template_string) @indent.ignore
[
(comment)
(ERROR)
] @indent.auto
(if_statement
consequence: (_) @indent.dedent
(#not-kind-eq? @indent.dedent statement_block)) @indent.begin
+222
View File
@@ -0,0 +1,222 @@
; SPDX-License-Identifier: Apache-2.0
; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter)
(((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)
(#set! injection.include-children)
; Languages excluded from auto-injection due to special rules
; - svg uses the html parser
; - css uses the styled parser
(#not-any-of? @injection.language "svg" "css"))
; svg`...` or svg(`...`)
(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.include-children)
(#set! injection.language "html"))
; Vercel PostgreSQL
; foo.sql`...` or foo.sql(`...`)
(call_expression
function: (member_expression
property: (property_identifier) @injection.language)
arguments: [
(arguments
(template_string) @injection.content)
(template_string) @injection.content
]
(#eq? @injection.language "sql")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children))
; Sanity CMS GROQ query
; defineQuery(`...`)
(call_expression
function: (identifier) @_name
(#eq? @_name "defineQuery")
arguments: (arguments
(template_string) @injection.content)
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "groq"))
; gql`...` or gql(`...`)
(call_expression
function: (identifier) @_name
(#eq? @_name "gql")
arguments: [
(arguments
(template_string) @injection.content)
(template_string) @injection.content
]
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#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.include-children)
(#set! injection.language "glimmer"))
; css`<css>`, keyframes`<css>`
(call_expression
function: (identifier) @_name
(#any-of? @_name "css" "keyframes")
arguments: (template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "styled"))
; 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.include-children)
(#set! injection.language "styled")))
; 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.include-children)
(#set! injection.language "styled")))
; 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.include-children)
(#set! injection.language "styled")))
; 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.include-children)
(#set! injection.language "styled")))
((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.include-children)
(#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.include-children)
(#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"))
;---- Angular injections -----
; @Component({
; template: `<html>`
; })
(decorator
(call_expression
function: ((identifier) @_name
(#eq? @_name "Component"))
arguments: (arguments
(object
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "template"))
value: ((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "angular")))))))
; @Component({
; styles: [`<css>`]
; })
(decorator
(call_expression
function: ((identifier) @_name
(#eq? @_name "Component"))
arguments: (arguments
(object
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "styles"))
value: (array
((template_string) @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.include-children)
(#set! injection.language "css"))))))))
; @Component({
; styles: `<css>`
; })
(decorator
(call_expression
function: ((identifier) @_name
(#eq? @_name "Component"))
arguments: (arguments
(object
(pair
key: ((property_identifier) @_prop
(#eq? @_prop "styles"))
value: ((template_string) @injection.content
(#set! injection.include-children)
(#offset! @injection.content 0 1 0 -1)
(#set! injection.language "css")))))))
+54
View File
@@ -0,0 +1,54 @@
; SPDX-License-Identifier: Apache-2.0
; Source: nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter)
; Scopes
;-------
(statement_block) @local.scope
(function_expression) @local.scope
(arrow_function) @local.scope
(function_declaration) @local.scope
(method_definition) @local.scope
(for_statement) @local.scope
(for_in_statement) @local.scope
(catch_clause) @local.scope
; Definitions
;------------
(variable_declarator
name: (identifier) @local.definition.var)
(variable_declarator
name: (object_pattern
(shorthand_property_identifier_pattern) @local.definition.var))
(variable_declarator
(object_pattern
(pair_pattern
(identifier) @local.definition.var)))
(import_specifier
(identifier) @local.definition.import)
(namespace_import
(identifier) @local.definition.import)
(function_declaration
(identifier) @local.definition.function
(#set! definition.var.scope parent))
(method_definition
(property_identifier) @local.definition.function
(#set! definition.var.scope parent))
; References
;------------
(identifier) @local.reference
(shorthand_property_identifier) @local.reference