mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-20 12:20:02 -04:00
feat(lua)!: switch from our fork to MunifTanjim's (#2272)
also take queries from https://github.com/MunifTanjim/nvim-treesitter-lua/tree/main/queries/lua BREAKING CHANGE: queries are not compatible; modules will have to update
This commit is contained in:
parent
668de0951a
commit
c80715f883
8 changed files with 189 additions and 206 deletions
|
|
@ -156,7 +156,7 @@
|
||||||
"revision": "3b213925b9c4f42c1acfe2e10bfbb438d9c6834d"
|
"revision": "3b213925b9c4f42c1acfe2e10bfbb438d9c6834d"
|
||||||
},
|
},
|
||||||
"lua": {
|
"lua": {
|
||||||
"revision": "6f5d40190ec8a0aa8c8410699353d820f4f7d7a6"
|
"revision": "6197f42bf174b867a499e201e40515b9feef12af"
|
||||||
},
|
},
|
||||||
"make": {
|
"make": {
|
||||||
"revision": "a4b9187417d6be349ee5fd4b6e77b4172c6827dd"
|
"revision": "a4b9187417d6be349ee5fd4b6e77b4172c6827dd"
|
||||||
|
|
|
||||||
|
|
@ -151,10 +151,11 @@ list.ledger = {
|
||||||
|
|
||||||
list.lua = {
|
list.lua = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = "https://github.com/nvim-treesitter/tree-sitter-lua",
|
url = "https://github.com/MunifTanjim/tree-sitter-lua",
|
||||||
files = { "src/parser.c", "src/scanner.cc" },
|
branch = "main",
|
||||||
|
files = { "src/parser.c", "src/scanner.c" },
|
||||||
},
|
},
|
||||||
maintainers = { "@vigoux" },
|
maintainers = { "@muniftanjim" },
|
||||||
}
|
}
|
||||||
|
|
||||||
list.python = {
|
list.python = {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
[
|
[
|
||||||
(for_in_statement)
|
(do_statement)
|
||||||
(for_statement)
|
|
||||||
(while_statement)
|
(while_statement)
|
||||||
(repeat_statement)
|
(repeat_statement)
|
||||||
(if_statement)
|
(if_statement)
|
||||||
(do_statement)
|
(for_statement)
|
||||||
|
(function_declaration)
|
||||||
(function_definition)
|
(function_definition)
|
||||||
(local_function)
|
(table_constructor)
|
||||||
(function)
|
|
||||||
(table)
|
|
||||||
] @fold
|
] @fold
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,34 @@
|
||||||
;;; Highlighting for lua
|
|
||||||
|
|
||||||
;;; Builtins
|
;;; Builtins
|
||||||
(self) @variable.builtin
|
|
||||||
|
[
|
||||||
|
(false)
|
||||||
|
(true)
|
||||||
|
] @boolean
|
||||||
|
|
||||||
|
(nil) @constant.builtin
|
||||||
|
|
||||||
|
((identifier) @variable.builtin
|
||||||
|
(#match? @variable.builtin "self"))
|
||||||
|
|
||||||
;; Keywords
|
;; Keywords
|
||||||
|
|
||||||
(if_statement
|
"return" @keyword.return
|
||||||
[
|
|
||||||
"if"
|
|
||||||
"then"
|
|
||||||
"end"
|
|
||||||
] @conditional)
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"else"
|
"goto"
|
||||||
"elseif"
|
"in"
|
||||||
"then"
|
"local"
|
||||||
] @conditional
|
] @keyword
|
||||||
|
|
||||||
(for_statement
|
(label_statement) @label
|
||||||
|
|
||||||
|
(break_statement) @keyword
|
||||||
|
|
||||||
|
(do_statement
|
||||||
[
|
[
|
||||||
"for"
|
|
||||||
"do"
|
"do"
|
||||||
"end"
|
"end"
|
||||||
] @repeat)
|
] @keyword)
|
||||||
|
|
||||||
(for_in_statement
|
|
||||||
[
|
|
||||||
"for"
|
|
||||||
"do"
|
|
||||||
"end"
|
|
||||||
] @repeat)
|
|
||||||
|
|
||||||
(while_statement
|
(while_statement
|
||||||
[
|
[
|
||||||
|
|
@ -45,57 +43,90 @@
|
||||||
"until"
|
"until"
|
||||||
] @repeat)
|
] @repeat)
|
||||||
|
|
||||||
(do_statement
|
(if_statement
|
||||||
[
|
[
|
||||||
|
"if"
|
||||||
|
"elseif"
|
||||||
|
"else"
|
||||||
|
"then"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(elseif_statement
|
||||||
|
[
|
||||||
|
"elseif"
|
||||||
|
"then"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(else_statement
|
||||||
|
[
|
||||||
|
"else"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(for_statement
|
||||||
|
[
|
||||||
|
"for"
|
||||||
"do"
|
"do"
|
||||||
"end"
|
"end"
|
||||||
] @keyword)
|
] @repeat)
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
[
|
[
|
||||||
"in"
|
"function"
|
||||||
"local"
|
"end"
|
||||||
(break_statement)
|
] @keyword.function)
|
||||||
"goto"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
"return" @keyword.return
|
(function_definition
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"end"
|
||||||
|
] @keyword.function)
|
||||||
|
|
||||||
;; Operators
|
;; Operators
|
||||||
|
|
||||||
[
|
[
|
||||||
"not"
|
|
||||||
"and"
|
"and"
|
||||||
|
"not"
|
||||||
"or"
|
"or"
|
||||||
] @keyword.operator
|
] @keyword.operator
|
||||||
|
|
||||||
[
|
[
|
||||||
"="
|
"+"
|
||||||
"~="
|
"-"
|
||||||
"=="
|
"*"
|
||||||
"<="
|
"/"
|
||||||
">="
|
"%"
|
||||||
"<"
|
"^"
|
||||||
">"
|
"#"
|
||||||
"+"
|
"=="
|
||||||
"-"
|
"~="
|
||||||
"%"
|
"<="
|
||||||
"/"
|
">="
|
||||||
"//"
|
"<"
|
||||||
"*"
|
">"
|
||||||
"^"
|
"="
|
||||||
"&"
|
"&"
|
||||||
"~"
|
"~"
|
||||||
"|"
|
"|"
|
||||||
">>"
|
"<<"
|
||||||
"<<"
|
">>"
|
||||||
".."
|
"//"
|
||||||
"#"
|
".."
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
;; Punctuation
|
;; Punctuations
|
||||||
["," "." ":" ";"] @punctuation.delimiter
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
":"
|
||||||
|
","
|
||||||
|
"."
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
;; Brackets
|
;; Brackets
|
||||||
|
|
||||||
[
|
[
|
||||||
"("
|
"("
|
||||||
")"
|
")"
|
||||||
|
|
@ -106,40 +137,41 @@
|
||||||
] @punctuation.bracket
|
] @punctuation.bracket
|
||||||
|
|
||||||
;; Variables
|
;; Variables
|
||||||
|
|
||||||
(identifier) @variable
|
(identifier) @variable
|
||||||
|
|
||||||
;; Constants
|
;; Constants
|
||||||
[
|
|
||||||
(false)
|
(vararg_expression) @constant
|
||||||
(true)
|
|
||||||
] @boolean
|
|
||||||
(nil) @constant.builtin
|
|
||||||
(spread) @constant ;; "..."
|
|
||||||
((identifier) @constant
|
((identifier) @constant
|
||||||
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
|
;; Tables
|
||||||
|
|
||||||
|
(field name: (identifier) @field)
|
||||||
|
|
||||||
|
(dot_index_expression field: (identifier) @field)
|
||||||
|
|
||||||
|
(table_constructor
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @constructor)
|
||||||
|
|
||||||
;; Functions
|
;; Functions
|
||||||
(function [(function_name) (identifier)] @function)
|
|
||||||
(function ["function" "end"] @keyword.function)
|
|
||||||
|
|
||||||
(local_function (identifier) @function)
|
(arguments (identifier) @parameter)
|
||||||
(local_function ["function" "end"] @keyword.function)
|
|
||||||
|
|
||||||
(variable_declaration
|
(parameters (identifier) @parameter)
|
||||||
(variable_declarator (identifier) @function) (function_definition))
|
|
||||||
(local_variable_declaration
|
|
||||||
(variable_declarator (identifier) @function) (function_definition))
|
|
||||||
|
|
||||||
(function_definition ["function" "end"] @keyword.function)
|
(function_call name: (identifier) @function)
|
||||||
|
(function_declaration name: (identifier) @function)
|
||||||
|
|
||||||
(property_identifier) @property
|
(function_call name: (dot_index_expression field: (identifier) @function))
|
||||||
|
(function_declaration name: (dot_index_expression field: (identifier) @function))
|
||||||
|
|
||||||
(function_call
|
(method_index_expression method: (identifier) @method)
|
||||||
[((identifier) @variable (method) @method)
|
|
||||||
((_) (method) @method)
|
|
||||||
(identifier) @function
|
|
||||||
(field_expression (property_identifier) @function)]
|
|
||||||
. (arguments))
|
|
||||||
|
|
||||||
(function_call
|
(function_call
|
||||||
(identifier) @function.builtin
|
(identifier) @function.builtin
|
||||||
|
|
@ -150,22 +182,15 @@
|
||||||
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
|
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
|
||||||
"tonumber" "tostring" "type" "unpack" "xpcall"))
|
"tonumber" "tostring" "type" "unpack" "xpcall"))
|
||||||
|
|
||||||
;; built-in next function
|
;; Others
|
||||||
(next) @function.builtin
|
|
||||||
|
|
||||||
;; Parameters
|
|
||||||
(parameters
|
|
||||||
(identifier) @parameter)
|
|
||||||
|
|
||||||
;; Nodes
|
|
||||||
(table ["{" "}"] @constructor)
|
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
(string) @string
|
|
||||||
|
(hash_bang_line) @comment
|
||||||
|
|
||||||
(number) @number
|
(number) @number
|
||||||
(label_statement) @label
|
|
||||||
; A bit of a tricky one, this will only match field names
|
(string) @string
|
||||||
(field . (identifier) @field (_))
|
|
||||||
(shebang) @comment
|
|
||||||
|
|
||||||
;; Error
|
;; Error
|
||||||
(ERROR) @error
|
(ERROR) @error
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,20 @@
|
||||||
[
|
[
|
||||||
(function_definition)
|
(function_definition)
|
||||||
|
(function_declaration)
|
||||||
(variable_declaration)
|
(variable_declaration)
|
||||||
(local_variable_declaration)
|
|
||||||
(field)
|
(field)
|
||||||
(local_function)
|
(do_statement)
|
||||||
(function)
|
(while_statement)
|
||||||
|
(repeat_statement)
|
||||||
(if_statement)
|
(if_statement)
|
||||||
(for_statement)
|
(for_statement)
|
||||||
(for_in_statement)
|
|
||||||
(repeat_statement)
|
|
||||||
(return_statement)
|
(return_statement)
|
||||||
(while_statement)
|
(table_constructor)
|
||||||
(table)
|
|
||||||
(arguments)
|
(arguments)
|
||||||
(do_statement)
|
|
||||||
] @indent
|
] @indent
|
||||||
|
|
||||||
|
@ignore
|
||||||
|
|
||||||
[
|
[
|
||||||
"end"
|
"end"
|
||||||
"until"
|
"until"
|
||||||
|
|
@ -24,8 +23,8 @@
|
||||||
"("
|
"("
|
||||||
")"
|
")"
|
||||||
"then"
|
"then"
|
||||||
(else)
|
(else_statement)
|
||||||
(elseif)
|
(elseif_statement)
|
||||||
] @branch
|
] @branch
|
||||||
|
|
||||||
(comment) @ignore
|
(comment) @ignore
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,14 @@
|
||||||
; C Injections
|
((function_call
|
||||||
(
|
name: [
|
||||||
(function_call
|
(identifier) @_cdef_identifier
|
||||||
(field_expression
|
(_ _ (identifier) @_cdef_identifier)
|
||||||
(property_identifier) @_cdef_identifier)
|
]
|
||||||
(arguments
|
arguments: (arguments (string content: _ @c)))
|
||||||
(string) @c)
|
(#eq? @_cdef_identifier "cdef"))
|
||||||
)
|
|
||||||
|
|
||||||
(#eq? @_cdef_identifier "cdef")
|
((function_call
|
||||||
(#lua-match? @c "^[\"']")
|
name: (_) @_vimcmd_identifier
|
||||||
(#offset! @c 0 1 0 -1)
|
arguments: (arguments (string content: _ @vim)))
|
||||||
)
|
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec"))
|
||||||
|
|
||||||
(
|
|
||||||
(function_call
|
|
||||||
(field_expression
|
|
||||||
(property_identifier) @_cdef_identifier)
|
|
||||||
(arguments
|
|
||||||
(string) @c)
|
|
||||||
)
|
|
||||||
|
|
||||||
(#eq? @_cdef_identifier "cdef")
|
|
||||||
(#lua-match? @c "^%[%[")
|
|
||||||
(#offset! @c 0 2 0 -2)
|
|
||||||
)
|
|
||||||
|
|
||||||
; Vimscript Injections
|
|
||||||
(
|
|
||||||
(function_call
|
|
||||||
(field_expression) @_vimcmd_identifier
|
|
||||||
(arguments
|
|
||||||
(string) @vim)
|
|
||||||
)
|
|
||||||
|
|
||||||
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec")
|
|
||||||
(#lua-match? @vim "^[\"']")
|
|
||||||
(#offset! @vim 0 1 0 -1)
|
|
||||||
)
|
|
||||||
|
|
||||||
(
|
|
||||||
(function_call
|
|
||||||
(field_expression) @_vimcmd_identifier
|
|
||||||
(arguments
|
|
||||||
(string) @vim)
|
|
||||||
)
|
|
||||||
|
|
||||||
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec")
|
|
||||||
(#lua-match? @vim "^%[%[")
|
|
||||||
(#offset! @vim 0 2 0 -2)
|
|
||||||
)
|
|
||||||
|
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,51 @@
|
||||||
;;; DECLARATIONS AND SCOPES
|
; Scopes
|
||||||
|
|
||||||
;; Variable and field declarations
|
|
||||||
((variable_declarator
|
|
||||||
(identifier) @definition.var))
|
|
||||||
|
|
||||||
((variable_declarator
|
|
||||||
(field_expression . (_) @definition.associated (property_identifier) @definition.var)))
|
|
||||||
|
|
||||||
;; Parameters
|
|
||||||
(parameters (identifier) @definition.parameter)
|
|
||||||
|
|
||||||
;; Loops
|
|
||||||
((loop_expression
|
|
||||||
(identifier) @definition.var))
|
|
||||||
|
|
||||||
;; Function definitions
|
|
||||||
((function
|
|
||||||
(function_name
|
|
||||||
(function_name_field
|
|
||||||
(identifier) @definition.associated . (property_identifier) @definition.method)))
|
|
||||||
(#set! definition.method.scope "parent"))
|
|
||||||
|
|
||||||
((function
|
|
||||||
(function_name (identifier) @definition.function))
|
|
||||||
(#set! definition.function.scope "parent"))
|
|
||||||
|
|
||||||
((local_function (identifier) @definition.function)
|
|
||||||
(#set! definition.function.scope "parent"))
|
|
||||||
|
|
||||||
(local_variable_declaration
|
|
||||||
(variable_declarator (identifier) @definition.function) . (function_definition))
|
|
||||||
|
|
||||||
;; Scopes
|
|
||||||
[
|
[
|
||||||
(program)
|
(chunk)
|
||||||
(function)
|
|
||||||
(local_function)
|
|
||||||
(function_definition)
|
|
||||||
(if_statement)
|
|
||||||
(for_in_statement)
|
|
||||||
(repeat_statement)
|
|
||||||
(while_statement)
|
|
||||||
(do_statement)
|
(do_statement)
|
||||||
|
(while_statement)
|
||||||
|
(repeat_statement)
|
||||||
|
(if_statement)
|
||||||
|
(for_statement)
|
||||||
|
(function_declaration)
|
||||||
|
(function_definition)
|
||||||
] @scope
|
] @scope
|
||||||
|
|
||||||
;;; REFERENCES
|
; Definitions
|
||||||
|
|
||||||
|
(assignment_statement
|
||||||
|
(variable_list
|
||||||
|
(identifier) @definition.var))
|
||||||
|
|
||||||
|
(assignment_statement
|
||||||
|
(variable_list
|
||||||
|
(dot_index_expression . (_) @definition.associated (identifier) @definition.var)))
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
|
name: (identifier) @definition.function)
|
||||||
|
(#set! definition.function.scope "parent")
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
|
name: (dot_index_expression
|
||||||
|
. (_) @definition.associated (identifier) @definition.function))
|
||||||
|
(#set! definition.method.scope "parent")
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
|
name: (method_index_expression
|
||||||
|
. (_) @definition.associated (identifier) @definition.method))
|
||||||
|
(#set! definition.method.scope "parent")
|
||||||
|
|
||||||
|
(for_generic_clause
|
||||||
|
(variable_list
|
||||||
|
(identifier) @definition.var))
|
||||||
|
|
||||||
|
(for_numeric_clause
|
||||||
|
name: (identifier) @definition.var)
|
||||||
|
|
||||||
|
(parameters (identifier) @definition.parameter)
|
||||||
|
|
||||||
|
; References
|
||||||
|
|
||||||
[
|
[
|
||||||
(identifier)
|
(identifier)
|
||||||
(property_identifier)
|
|
||||||
] @reference
|
] @reference
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ local run = Runner:new(it, "tests/indent/lua", {
|
||||||
describe("indent Lua:", function()
|
describe("indent Lua:", function()
|
||||||
describe("whole file:", function()
|
describe("whole file:", function()
|
||||||
run:whole_file(".", { expected_failures = {
|
run:whole_file(".", { expected_failures = {
|
||||||
"./string.lua",
|
|
||||||
"./comment.lua",
|
"./comment.lua",
|
||||||
} })
|
} })
|
||||||
end)
|
end)
|
||||||
|
|
@ -29,7 +28,7 @@ describe("indent Lua:", function()
|
||||||
run:new_line("table.lua", { on_line = 1, text = "b = 0,", indent = 2 })
|
run:new_line("table.lua", { on_line = 1, text = "b = 0,", indent = 2 })
|
||||||
run:new_line("table.lua", { on_line = 5, text = "4,", indent = 4 })
|
run:new_line("table.lua", { on_line = 5, text = "4,", indent = 4 })
|
||||||
run:new_line("table.lua", { on_line = 7, text = "4,", indent = 4 })
|
run:new_line("table.lua", { on_line = 7, text = "4,", indent = 4 })
|
||||||
run:new_line("loop.lua", { on_line = 4, text = "x = x + 1", indent = 2 })
|
run:new_line("loop.lua", { on_line = 4, text = "x = x + 1", indent = 2 }, "expected failure", XFAIL)
|
||||||
run:new_line("cond.lua", { on_line = 5, text = "x = x + 1", indent = 2 })
|
run:new_line("cond.lua", { on_line = 5, text = "x = x + 1", indent = 2 })
|
||||||
run:new_line("cond.lua", { on_line = 7, text = "x = x + 1", indent = 2 })
|
run:new_line("cond.lua", { on_line = 7, text = "x = x + 1", indent = 2 })
|
||||||
run:new_line("cond.lua", { on_line = 8, text = "x = x + 1", indent = 4 })
|
run:new_line("cond.lua", { on_line = 8, text = "x = x + 1", indent = 4 })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue