mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-05 21:10:15 -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"
|
||||
},
|
||||
"lua": {
|
||||
"revision": "6f5d40190ec8a0aa8c8410699353d820f4f7d7a6"
|
||||
"revision": "6197f42bf174b867a499e201e40515b9feef12af"
|
||||
},
|
||||
"make": {
|
||||
"revision": "a4b9187417d6be349ee5fd4b6e77b4172c6827dd"
|
||||
|
|
|
|||
|
|
@ -151,10 +151,11 @@ list.ledger = {
|
|||
|
||||
list.lua = {
|
||||
install_info = {
|
||||
url = "https://github.com/nvim-treesitter/tree-sitter-lua",
|
||||
files = { "src/parser.c", "src/scanner.cc" },
|
||||
url = "https://github.com/MunifTanjim/tree-sitter-lua",
|
||||
branch = "main",
|
||||
files = { "src/parser.c", "src/scanner.c" },
|
||||
},
|
||||
maintainers = { "@vigoux" },
|
||||
maintainers = { "@muniftanjim" },
|
||||
}
|
||||
|
||||
list.python = {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
[
|
||||
(for_in_statement)
|
||||
(for_statement)
|
||||
(do_statement)
|
||||
(while_statement)
|
||||
(repeat_statement)
|
||||
(if_statement)
|
||||
(do_statement)
|
||||
(for_statement)
|
||||
(function_declaration)
|
||||
(function_definition)
|
||||
(local_function)
|
||||
(function)
|
||||
(table)
|
||||
(table_constructor)
|
||||
] @fold
|
||||
|
|
|
|||
|
|
@ -1,36 +1,34 @@
|
|||
;;; Highlighting for lua
|
||||
|
||||
;;; Builtins
|
||||
(self) @variable.builtin
|
||||
|
||||
[
|
||||
(false)
|
||||
(true)
|
||||
] @boolean
|
||||
|
||||
(nil) @constant.builtin
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#match? @variable.builtin "self"))
|
||||
|
||||
;; Keywords
|
||||
|
||||
(if_statement
|
||||
[
|
||||
"if"
|
||||
"then"
|
||||
"end"
|
||||
] @conditional)
|
||||
"return" @keyword.return
|
||||
|
||||
[
|
||||
"else"
|
||||
"elseif"
|
||||
"then"
|
||||
] @conditional
|
||||
"goto"
|
||||
"in"
|
||||
"local"
|
||||
] @keyword
|
||||
|
||||
(for_statement
|
||||
(label_statement) @label
|
||||
|
||||
(break_statement) @keyword
|
||||
|
||||
(do_statement
|
||||
[
|
||||
"for"
|
||||
"do"
|
||||
"end"
|
||||
] @repeat)
|
||||
|
||||
(for_in_statement
|
||||
[
|
||||
"for"
|
||||
"do"
|
||||
"end"
|
||||
] @repeat)
|
||||
] @keyword)
|
||||
|
||||
(while_statement
|
||||
[
|
||||
|
|
@ -45,57 +43,90 @@
|
|||
"until"
|
||||
] @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"
|
||||
"end"
|
||||
] @keyword)
|
||||
] @repeat)
|
||||
|
||||
(function_declaration
|
||||
[
|
||||
"in"
|
||||
"local"
|
||||
(break_statement)
|
||||
"goto"
|
||||
] @keyword
|
||||
"function"
|
||||
"end"
|
||||
] @keyword.function)
|
||||
|
||||
"return" @keyword.return
|
||||
(function_definition
|
||||
[
|
||||
"function"
|
||||
"end"
|
||||
] @keyword.function)
|
||||
|
||||
;; Operators
|
||||
|
||||
[
|
||||
"not"
|
||||
"and"
|
||||
"not"
|
||||
"or"
|
||||
] @keyword.operator
|
||||
|
||||
[
|
||||
"="
|
||||
"~="
|
||||
"=="
|
||||
"<="
|
||||
">="
|
||||
"<"
|
||||
">"
|
||||
"+"
|
||||
"-"
|
||||
"%"
|
||||
"/"
|
||||
"//"
|
||||
"*"
|
||||
"^"
|
||||
"&"
|
||||
"~"
|
||||
"|"
|
||||
">>"
|
||||
"<<"
|
||||
".."
|
||||
"#"
|
||||
] @operator
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"%"
|
||||
"^"
|
||||
"#"
|
||||
"=="
|
||||
"~="
|
||||
"<="
|
||||
">="
|
||||
"<"
|
||||
">"
|
||||
"="
|
||||
"&"
|
||||
"~"
|
||||
"|"
|
||||
"<<"
|
||||
">>"
|
||||
"//"
|
||||
".."
|
||||
] @operator
|
||||
|
||||
;; Punctuation
|
||||
["," "." ":" ";"] @punctuation.delimiter
|
||||
;; Punctuations
|
||||
|
||||
[
|
||||
";"
|
||||
":"
|
||||
","
|
||||
"."
|
||||
] @punctuation.delimiter
|
||||
|
||||
;; Brackets
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
|
|
@ -106,40 +137,41 @@
|
|||
] @punctuation.bracket
|
||||
|
||||
;; Variables
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
;; Constants
|
||||
[
|
||||
(false)
|
||||
(true)
|
||||
] @boolean
|
||||
(nil) @constant.builtin
|
||||
(spread) @constant ;; "..."
|
||||
|
||||
(vararg_expression) @constant
|
||||
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||
|
||||
;; Tables
|
||||
|
||||
(field name: (identifier) @field)
|
||||
|
||||
(dot_index_expression field: (identifier) @field)
|
||||
|
||||
(table_constructor
|
||||
[
|
||||
"{"
|
||||
"}"
|
||||
] @constructor)
|
||||
|
||||
;; Functions
|
||||
(function [(function_name) (identifier)] @function)
|
||||
(function ["function" "end"] @keyword.function)
|
||||
|
||||
(local_function (identifier) @function)
|
||||
(local_function ["function" "end"] @keyword.function)
|
||||
(arguments (identifier) @parameter)
|
||||
|
||||
(variable_declaration
|
||||
(variable_declarator (identifier) @function) (function_definition))
|
||||
(local_variable_declaration
|
||||
(variable_declarator (identifier) @function) (function_definition))
|
||||
(parameters (identifier) @parameter)
|
||||
|
||||
(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
|
||||
[((identifier) @variable (method) @method)
|
||||
((_) (method) @method)
|
||||
(identifier) @function
|
||||
(field_expression (property_identifier) @function)]
|
||||
. (arguments))
|
||||
(method_index_expression method: (identifier) @method)
|
||||
|
||||
(function_call
|
||||
(identifier) @function.builtin
|
||||
|
|
@ -150,22 +182,15 @@
|
|||
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
|
||||
"tonumber" "tostring" "type" "unpack" "xpcall"))
|
||||
|
||||
;; built-in next function
|
||||
(next) @function.builtin
|
||||
;; Others
|
||||
|
||||
;; Parameters
|
||||
(parameters
|
||||
(identifier) @parameter)
|
||||
|
||||
;; Nodes
|
||||
(table ["{" "}"] @constructor)
|
||||
(comment) @comment
|
||||
(string) @string
|
||||
|
||||
(hash_bang_line) @comment
|
||||
|
||||
(number) @number
|
||||
(label_statement) @label
|
||||
; A bit of a tricky one, this will only match field names
|
||||
(field . (identifier) @field (_))
|
||||
(shebang) @comment
|
||||
|
||||
(string) @string
|
||||
|
||||
;; Error
|
||||
(ERROR) @error
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
[
|
||||
(function_definition)
|
||||
(function_declaration)
|
||||
(variable_declaration)
|
||||
(local_variable_declaration)
|
||||
(field)
|
||||
(local_function)
|
||||
(function)
|
||||
(do_statement)
|
||||
(while_statement)
|
||||
(repeat_statement)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(for_in_statement)
|
||||
(repeat_statement)
|
||||
(return_statement)
|
||||
(while_statement)
|
||||
(table)
|
||||
(table_constructor)
|
||||
(arguments)
|
||||
(do_statement)
|
||||
] @indent
|
||||
|
||||
@ignore
|
||||
|
||||
[
|
||||
"end"
|
||||
"until"
|
||||
|
|
@ -24,8 +23,8 @@
|
|||
"("
|
||||
")"
|
||||
"then"
|
||||
(else)
|
||||
(elseif)
|
||||
(else_statement)
|
||||
(elseif_statement)
|
||||
] @branch
|
||||
|
||||
(comment) @ignore
|
||||
|
|
|
|||
|
|
@ -1,53 +1,14 @@
|
|||
; C Injections
|
||||
(
|
||||
(function_call
|
||||
(field_expression
|
||||
(property_identifier) @_cdef_identifier)
|
||||
(arguments
|
||||
(string) @c)
|
||||
)
|
||||
((function_call
|
||||
name: [
|
||||
(identifier) @_cdef_identifier
|
||||
(_ _ (identifier) @_cdef_identifier)
|
||||
]
|
||||
arguments: (arguments (string content: _ @c)))
|
||||
(#eq? @_cdef_identifier "cdef"))
|
||||
|
||||
(#eq? @_cdef_identifier "cdef")
|
||||
(#lua-match? @c "^[\"']")
|
||||
(#offset! @c 0 1 0 -1)
|
||||
)
|
||||
|
||||
(
|
||||
(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)
|
||||
)
|
||||
((function_call
|
||||
name: (_) @_vimcmd_identifier
|
||||
arguments: (arguments (string content: _ @vim)))
|
||||
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec"))
|
||||
|
||||
(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)
|
||||
(function)
|
||||
(local_function)
|
||||
(function_definition)
|
||||
(if_statement)
|
||||
(for_in_statement)
|
||||
(repeat_statement)
|
||||
(while_statement)
|
||||
(chunk)
|
||||
(do_statement)
|
||||
(while_statement)
|
||||
(repeat_statement)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(function_declaration)
|
||||
(function_definition)
|
||||
] @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)
|
||||
(property_identifier)
|
||||
] @reference
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ local run = Runner:new(it, "tests/indent/lua", {
|
|||
describe("indent Lua:", function()
|
||||
describe("whole file:", function()
|
||||
run:whole_file(".", { expected_failures = {
|
||||
"./string.lua",
|
||||
"./comment.lua",
|
||||
} })
|
||||
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 = 5, 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 = 7, text = "x = x + 1", indent = 2 })
|
||||
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