on master help sign in
Update tree-sitter-lua and add textobjects for Lua (#3552)
a24fae3Lennard Hofmann
book/src/generated/lang-support.md+1−1
@@ -66,7 +66,7 @@
66| llvm | ✓ | ✓ | ✓ | |
66| llvm | ✓ | ✓ | ✓ | |
67| llvm-mir | ✓ | ✓ | ✓ | |
67| llvm-mir | ✓ | ✓ | ✓ | |
68| llvm-mir-yaml | ✓ | | ✓ | |
68| llvm-mir-yaml | ✓ | | ✓ | |
69−| lua | ✓ | | ✓ | `lua-language-server` |
69+| lua | ✓ | ✓ | ✓ | `lua-language-server` |
70| make | ✓ | | | |
70| make | ✓ | | | |
71| markdown | ✓ | | | `marksman` |
71| markdown | ✓ | | | `marksman` |
72| markdown.inline | ✓ | | | |
72| markdown.inline | ✓ | | | |
languages.toml+1−1
@@ -667,7 +667,7 @@ language-server = { command = "lua-language-server", args = [] }
667
667
668[[grammar]]
668[[grammar]]
669name = "lua"
669name = "lua"
670−source = { git = "https://github.com/nvim-treesitter/tree-sitter-lua", rev = "6f5d40190ec8a0aa8c8410699353d820f4f7d7a6" }
670+source = { git = "https://github.com/MunifTanjim/tree-sitter-lua", rev = "887dfd4e83c469300c279314ff1619b1d0b85b91" }
671
671
672[[language]]
672[[language]]
673name = "svelte"
673name = "svelte"
runtime/queries/lua/folds.scmnew file+10
@@ -0,0 +1,10 @@
1+[
2+ (do_statement)
3+ (while_statement)
4+ (repeat_statement)
5+ (if_statement)
6+ (for_statement)
7+ (function_declaration)
8+ (function_definition)
9+ (table_constructor)
10+] @fold
runtime/queries/lua/highlights.scm+40−37
@@ -1,7 +1,8 @@
1;;; Highlighting for lua
1;;; Highlighting for lua
2
2
3;;; Builtins
3;;; Builtins
4−(self) @variable.builtin
4+((identifier) @variable.builtin
5+ (#eq? @variable.builtin "self"))
5
6
6;; Keywords
7;; Keywords
7
8
@@ -12,20 +13,20 @@
12 "end"
13 "end"
13] @keyword.control.conditional)
14] @keyword.control.conditional)
14
15
16+(elseif_statement
15[
17[
16− "else"
17 "elseif"
18 "elseif"
18 "then"
19 "then"
20+ "end"
19−] @keyword.control.conditional
21+] @keyword.control.conditional)
20
22
21−(for_statement
23+(else_statement
22[
24[
23− "for"
25+ "else"
24− "do"
25 "end"
26 "end"
26−] @keyword.control.repeat)
27+] @keyword.control.conditional)
27
28
28−(for_in_statement
29+(for_statement
29[
30[
30 "for"
31 "for"
31 "do"
32 "do"
@@ -51,21 +52,34 @@
51 "end"
52 "end"
52] @keyword)
53] @keyword)
53
54
55+"return" @keyword.control.return
56+
54[
57[
55 "in"
58 "in"
56 "local"
59 "local"
57 (break_statement)
60 (break_statement)
58 "goto"
61 "goto"
59− "return"
60] @keyword
62] @keyword
61
63
64+(function_declaration
65+[
66+ "function"
67+ "end"
68+] @keyword.function)
69+
70+(function_definition
71+[
72+ "function"
73+ "end"
74+] @keyword.function)
75+
62;; Operators
76;; Operators
63
77
64[
78[
65 "not"
79 "not"
66 "and"
80 "and"
67 "or"
81 "or"
68−] @operator
82+] @keyword.operator
69
83
70[
84[
71"="
85"="
@@ -95,6 +109,7 @@
95["," "." ":" ";"] @punctuation.delimiter
109["," "." ":" ";"] @punctuation.delimiter
96
110
97;; Brackets
111;; Brackets
112+
98[
113[
99 "("
114 "("
100 ")"
115 ")"
@@ -110,7 +125,8 @@
110(true)
125(true)
111] @constant.builtin.boolean
126] @constant.builtin.boolean
112(nil) @constant.builtin
127(nil) @constant.builtin
113−(spread) @constant ;; "..."
128+(vararg_expression) @constant
129+
114((identifier) @constant
130((identifier) @constant
115 (#match? @constant "^[A-Z][A-Z_0-9]*$"))
131 (#match? @constant "^[A-Z][A-Z_0-9]*$"))
116
132
@@ -119,45 +135,32 @@
119 (identifier) @variable.parameter)
135 (identifier) @variable.parameter)
120
136
121; ;; Functions
137; ;; Functions
122−(function [(function_name) (identifier)] @function)
138+(function_declaration name: (identifier) @function)
123−(function ["function" "end"] @keyword.function)
124−
125−(function
126− (function_name
127− (function_name_field
128− (property_identifier) @function .)))
129−
130−(local_function (identifier) @function)
139+(function_call name: (identifier) @function.call)
131−(local_function ["function" "end"] @keyword.function)
132
140
133−(variable_declaration
141+(function_declaration name: (dot_index_expression field: (identifier) @function))
134− (variable_declarator (identifier) @function) (function_definition))
142+(function_call name: (dot_index_expression field: (identifier) @function.call))
135−(local_variable_declaration
136− (variable_declarator (identifier) @function) (function_definition))
137
143
138−(function_definition ["function" "end"] @keyword.function)
144+; TODO: incorrectly highlights variable N in `N, nop = 42, function() end`
145+(assignment_statement
146+ (variable_list
147+ name: (identifier) @function)
148+ (expression_list
149+ value: (function_definition)))
139
150
140−(function_call
151+(method_index_expression method: (identifier) @function.method)
141− [
142− ((identifier) @variable (method) @function.method)
143− ((_) (method) @function.method)
144− (identifier) @function
145− (field_expression (property_identifier) @function)
146− ]
147− . (arguments))
148
152
149;; Nodes
153;; Nodes
150−(table ["{" "}"] @constructor)
151(comment) @comment
154(comment) @comment
152(string) @string
155(string) @string
153(number) @constant.numeric.integer
156(number) @constant.numeric.integer
154(label_statement) @label
157(label_statement) @label
155; A bit of a tricky one, this will only match field names
158; A bit of a tricky one, this will only match field names
156(field . (identifier) @variable.other.member (_))
159(field . (identifier) @variable.other.member (_))
157−(shebang) @comment
160+(hash_bang_line) @comment
158
161
159;; Property
162;; Property
160−(property_identifier) @variable.other.member
163+(dot_index_expression field: (identifier) @variable.other.member)
161
164
162;; Variable
165;; Variable
163(identifier) @variable
166(identifier) @variable
runtime/queries/lua/indents.scm+3−7
@@ -1,17 +1,13 @@
1[
1[
2 (function_definition)
2 (function_definition)
3− (variable_declaration)
3+ (function_declaration)
4− (local_variable_declaration)
4+ (method_index_expression)
5 (field)
5 (field)
6− (local_function)
7− (function)
8 (if_statement)
6 (if_statement)
9 (for_statement)
7 (for_statement)
10− (for_in_statement)
11 (repeat_statement)
8 (repeat_statement)
12− (return_statement)
13 (while_statement)
9 (while_statement)
14− (table)
10+ (table_constructor)
15 (arguments)
11 (arguments)
16 (do_statement)
12 (do_statement)
17] @indent
13] @indent
runtime/queries/lua/injections.scm+2−1
@@ -1,2 +1,3 @@
1((comment) @injection.content
1((comment) @injection.content
2− (#set! injection.language "comment"))
2+ (#set! injection.language "comment")
3+ (#set! injection.include-children))
runtime/queries/lua/textobjects.scmnew file+15
@@ -0,0 +1,15 @@
1+(function_definition
2+ body: (_) @function.inside) @function.around
3+
4+(function_declaration
5+ body: (_) @function.inside) @function.around
6+
7+(parameters
8+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
9+
10+(arguments
11+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
12+
13+(comment) @comment.inside
14+
15+(comment)+ @comment.around