aboutsummaryrefslogtreecommitdiffstats
path: root/queries/lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2022-01-18 22:15:26 +0100
committerGitHub <noreply@github.com>2022-01-18 22:15:26 +0100
commitc80715f883b8c7963782973b23297c5dec7924be (patch)
tree3ae4ea4499db6824abd65be4b4f2931a6b8a2864 /queries/lua
parentchore: remove swift tests for now (cause CI failure) (diff)
downloadnvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.tar
nvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.tar.gz
nvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.tar.bz2
nvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.tar.lz
nvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.tar.xz
nvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.tar.zst
nvim-treesitter-c80715f883b8c7963782973b23297c5dec7924be.zip
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
Diffstat (limited to 'queries/lua')
-rw-r--r--queries/lua/folds.scm10
-rw-r--r--queries/lua/highlights.scm205
-rw-r--r--queries/lua/indents.scm19
-rw-r--r--queries/lua/injections.scm61
-rw-r--r--queries/lua/locals.scm76
5 files changed, 177 insertions, 194 deletions
diff --git a/queries/lua/folds.scm b/queries/lua/folds.scm
index b57e722f6..d8f0b42df 100644
--- a/queries/lua/folds.scm
+++ b/queries/lua/folds.scm
@@ -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
diff --git a/queries/lua/highlights.scm b/queries/lua/highlights.scm
index 6433815c8..03b3090a6 100644
--- a/queries/lua/highlights.scm
+++ b/queries/lua/highlights.scm
@@ -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
-[
- "for"
- "do"
- "end"
-] @repeat)
+(label_statement) @label
+
+(break_statement) @keyword
-(for_in_statement
+(do_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
-
-;; Parameters
-(parameters
- (identifier) @parameter)
+;; Others
-;; 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
diff --git a/queries/lua/indents.scm b/queries/lua/indents.scm
index e7465aa06..d0a16d20f 100644
--- a/queries/lua/indents.scm
+++ b/queries/lua/indents.scm
@@ -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
diff --git a/queries/lua/injections.scm b/queries/lua/injections.scm
index fa05c40a7..20215a15e 100644
--- a/queries/lua/injections.scm
+++ b/queries/lua/injections.scm
@@ -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
diff --git a/queries/lua/locals.scm b/queries/lua/locals.scm
index 9cf672398..1fad4a1ed 100644
--- a/queries/lua/locals.scm
+++ b/queries/lua/locals.scm
@@ -1,51 +1,51 @@
-;;; DECLARATIONS AND SCOPES
+; Scopes
-;; Variable and field declarations
-((variable_declarator
- (identifier) @definition.var))
+[
+ (chunk)
+ (do_statement)
+ (while_statement)
+ (repeat_statement)
+ (if_statement)
+ (for_statement)
+ (function_declaration)
+ (function_definition)
+] @scope
-((variable_declarator
- (field_expression . (_) @definition.associated (property_identifier) @definition.var)))
+; Definitions
-;; Parameters
-(parameters (identifier) @definition.parameter)
+(assignment_statement
+ (variable_list
+ (identifier) @definition.var))
-;; Loops
-((loop_expression
- (identifier) @definition.var))
+(assignment_statement
+ (variable_list
+ (dot_index_expression . (_) @definition.associated (identifier) @definition.var)))
-;; Function definitions
-((function
- (function_name
- (function_name_field
- (identifier) @definition.associated . (property_identifier) @definition.method)))
- (#set! definition.method.scope "parent"))
+(function_declaration
+ name: (identifier) @definition.function)
+ (#set! definition.function.scope "parent")
-((function
- (function_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")
-((local_function (identifier) @definition.function)
- (#set! definition.function.scope "parent"))
+(function_declaration
+ name: (method_index_expression
+ . (_) @definition.associated (identifier) @definition.method))
+ (#set! definition.method.scope "parent")
-(local_variable_declaration
- (variable_declarator (identifier) @definition.function) . (function_definition))
+(for_generic_clause
+ (variable_list
+ (identifier) @definition.var))
-;; Scopes
-[
- (program)
- (function)
- (local_function)
- (function_definition)
- (if_statement)
- (for_in_statement)
- (repeat_statement)
- (while_statement)
- (do_statement)
-] @scope
+(for_numeric_clause
+ name: (identifier) @definition.var)
+
+(parameters (identifier) @definition.parameter)
+
+; References
-;;; REFERENCES
[
(identifier)
- (property_identifier)
] @reference