Skip to content

Commit 41e03dc

Browse files
committed
feat: highlight lua and luau string interpolation in string.format
1 parent f4557d0 commit 41e03dc

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
| log || | | | |
148148
| lpf || | | | |
149149
| lua |||| | `lua-language-server` |
150+
| lua-format-string || | | | |
150151
| luau |||| | `luau-lsp` |
151152
| mail ||| | | |
152153
| make || || | |

languages.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,16 @@ language-servers = [ "lua-language-server" ]
14161416
name = "lua"
14171417
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-lua", rev = "88e446476a1e97a8724dff7a23e2d709855077f2" }
14181418

1419+
[[language]]
1420+
name = "lua-format-string"
1421+
scope = "source.lua-format-string"
1422+
file-types = []
1423+
injection-regex = "lua-format-string"
1424+
1425+
[[grammar]]
1426+
name = "lua-format-string"
1427+
source = { git = "https://codeberg.org/kpbaks/tree-sitter-lua-format-string", rev = "b667c8cab109df307e1b4d56b0b43f5c4a353533" }
1428+
14191429
[[grammar]]
14201430
name = "teal"
14211431
source = { git = "https://github.com/euclidianAce/tree-sitter-teal", rev = "3db655924b2ff1c54fdf6371b5425ea6b5dccefe" }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(escaped_percent_sign) @constant.character.escape
2+
3+
(flag) @constant.builtin
4+
5+
(text) @string
6+
7+
(width) @constant.numeric.integer
8+
(precision) @constant.numeric.float
9+
10+
(conversion_specifier) @type
11+
12+
"." @punctuation.delimiter
13+
"%" @punctuation.special

runtime/queries/lua/injections.scm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
((comment) @injection.content
22
(#set! injection.language "comment")
33
(#set! injection.include-children))
4+
5+
; string.format("format string", ...)
6+
((function_call
7+
name: (dot_index_expression
8+
table: (identifier) @_table
9+
field: (identifier) @_function)
10+
arguments: (arguments
11+
.
12+
(string
13+
content: (string_content) @injection.content)))
14+
(#eq? @_table "string")
15+
(#eq? @_function "format")
16+
(#set! injection.language "lua-format-string"))
17+
18+
; ("format"):format(...)
19+
((function_call
20+
name: (method_index_expression
21+
table: (parenthesized_expression
22+
(string
23+
content: (string_content) @injection.content))
24+
method: (identifier) @_function))
25+
(#eq? @_function "format")
26+
(#set! injection.language "lua-format-string"))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
((comment) @injection.content
22
(#set! injection.language "comment"))
3+
4+
; string.format("format string", ...)
5+
((call_stmt
6+
invoked: (var
7+
table_name: (name) @_table
8+
(key
9+
field_name: (name) @_function))
10+
(arglist
11+
. (string) @injection.content))
12+
(#eq? @_table "string")
13+
(#eq? @_function "format")
14+
(#set! injection.language "lua-format-string"))
15+
16+
; ("format"):format(...)
17+
((call_stmt
18+
method_table: (exp_wrap (string) @injection.content)
19+
method_name: (name) @_function)
20+
(#eq? @_function "format")
21+
(#set! injection.language "lua-format-string"))

0 commit comments

Comments
 (0)