-
Notifications
You must be signed in to change notification settings - Fork 2
/
preset_injections.lua
277 lines (271 loc) · 8.43 KB
/
preset_injections.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
local preset_injections = {
go = {
sql = {
code = [[; SQL syntax highlighting within strings (NVIM v0.9.4)
(
[
(raw_string_literal)
(interpreted_string_literal)
] @injection.content
(#match? @injection.content "(SELECT|INSERT|UPDATE|DELETE).+(FROM|INTO|VALUES|SET).*(WHERE|GROUP BY)?")
(#set! injection.language "sql")
)]],
description = "SQL syntax highlighting within strings (NVIM v0.10.0)",
},
},
typescript = {
sql_for_parts = {
code = [[
(
[
(string_fragment)
] @injection.content
(#match? @injection.content "(SELECT|INSERT|UPDATE|DELETE).+(FROM|INTO|VALUES|SET).*(WHERE|GROUP BY)?")
(#set! injection.language "sql")
)
(
[
(template_string)
] @injection.content
(#match? @injection.content "(SELECT|INSERT|UPDATE|DELETE).+(FROM|INTO|VALUES|SET).*(WHERE|GROUP BY)?")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.language "sql")
)
]],
description = "SQL syntax highlighting within strings (NVIM v0.10.0)",
},
},
javascript = {
sql_for_parts = {
code = [[
(
[
(string_fragment)
] @injection.content
(#match? @injection.content "(SELECT|INSERT|UPDATE|DELETE).+(FROM|INTO|VALUES|SET).*(WHERE|GROUP BY)?")
(#set! injection.language "sql")
)
(
[
(template_string)
] @injection.content
(#match? @injection.content "(SELECT|INSERT|UPDATE|DELETE).+(FROM|INTO|VALUES|SET).*(WHERE|GROUP BY)?")
(#offset! @injection.content 0 1 0 -1)
(#set! injection.language "sql")
)
]],
description = "SQL syntax highlighting within strings (NVIM v0.10.0)",
},
quotes_indicator = {
code = [[
; variable (with angled quotes)
; /* html */ `<html>`
; /* sql */ `SELECT * FROM foo`
(variable_declarator
(comment) @injection.language (#offset! @injection.language 0 3 0 -3)
(template_string) @injection.content (#offset! @injection.content 0 1 0 -1)
)
; variable (with single/double quotes)
(variable_declarator
(comment) @injection.language (#offset! @injection.language 0 3 0 -3)
(string (string_fragment) @injection.content)
)
; argument (with angled quotes)
; foo(/* html */ `<span>`)
; foo(/* sql */ `SELECT * FROM foo`)
(call_expression
arguments:
[
(arguments
(comment) @injection.language (#offset! @injection.language 0 3 0 -3)
(template_string) @injection.content (#offset! @injection.content 0 1 0 -1)
)
]
)
; argument (with single/double quotes)
(call_expression
arguments:
[
(arguments
(comment) @injection.language (#offset! @injection.language 0 3 0 -3)
(string (string_fragment) @injection.content)
)
]
)
]],
description = [[
const myhtml = /* html */ ` <html> <body></body> </html> `;
const mysql = /* sql */ `SELECT * FROM foo`;
foo(/* html */ `<span>`)]],
},
},
html = {
xdata = {
code = [[
((element
(start_tag
(attribute
(attribute_name) @_name
(quoted_attribute_value (attribute_value) @injection.content))))
(#eq? @_name "x-data")
(#set! injection.language javascript))
]],
description = "x-data element attributes as javascript",
},
pythoncode = {
code = [[
(element
(start_tag
(attribute
(quoted_attribute_value
((attribute_value) @_idd (#eq? @_idd "python")))))
((text) @injection.content (#set! injection.language "python")))
]],
description = "Python syntax in all text elements in HTML that have an attribute set to 'python' ",
},
luacode = {
code = [[
(element
(start_tag
(attribute
(quoted_attribute_value
((attribute_value) @_idd (#eq? @_idd "lua")))))
((text) @injection.content (#set! injection.language "lua")))
]],
description = "Lua syntax in all text elements in HTML that have an attribute set to 'lua' ",
},
},
lua = {
system_cmd = {
code = [[
(function_call
name: ((dot_index_expression) @_mm
(#any-of? @_mm "vim.fn.system" "vim.system"))
arguments: (arguments
( string content:
(string_content) @injection.content
(#set! injection.language "bash"))))]],
description = "bash highlighting in lua vim.system and vim.fn.system",
},
},
markdown = {
codeblocks_as_lua = {
code = [[((code_fence_content) @injection.content (#set! injection.language "lua"))]],
},
},
rust = {
html_templates = {
code = [[(
(raw_string_literal) @html
(#match? @html "*DOCTYPE.*")
(#set! injection.language "html")
) @injection.content]],
description = "HTML syntax in all text elements which have a DOCTYPE substring",
},
},
python = {
vue_for_add_slot = {
code = [[
(call
function: (attribute attribute: (identifier) @id (#match? @id "add_slot"))
arguments: (argument_list
(string (string_content) @injection.content (#set! injection.language "vue"))))
]],
description = "In NiceGUI, you can add a template slot for elements. This is in ",
},
sql_in_call = {
code = [[
(call
function: (attribute attribute: (identifier) @id (#match? @id "execute|read_sql"))
arguments: (argument_list
(string (string_content) @injection.content (#set! injection.language "sql"))))
]],
description = "SQL syntax for strings which reside inside a `execute` or `read_sql` funciton call",
},
all_sql = {
code = [[
(string
(string_content) @injection.content
(#vim-match? @injection.content "^\w*SELECT|FROM|INNER JOIN|WHERE|CREATE|DROP|INSERT|UPDATE|ALTER.*$")
(#set! injection.language "sql"))
]],
description = "SQL syntax for all strings containing uppercase SQL commands",
},
rst_for_docstring = {
code = [[
(function_definition
(block
(expression_statement
(string
(string_content) @injection.content (#set! injection.language "rst")))))
]],
description = "restructured text syntax in all python docstrings",
},
javascript_variables = {
code = [[
(assignment
((identifier) @_varx (#match? @_varx ".*js$"))
(string
(string_content) @injection.content (#set! injection.language "javascript")))
]],
description = "JavaScript syntax in all strings in assignments of identifiers that end with 'js'",
},
html_variables = {
code = [[
(assignment
((identifier) @_varx (#match? @_varx ".*[hH][tT][mM][lL]$"))
(string
(string_content) @injection.content (#set! injection.language "html")))
]],
description = "HTML syntax in all strings in assignments of identifiers that end with 'html'",
},
css_variables = {
code = [[
(assignment
((identifier) @_varx (#match? @_varx ".*css$"))
(string
(string_content) @injection.content (#set! injection.language "css")))
]],
description = "CSS syntax in all strings in assignments of identifiers that end with 'css'",
},
style_attribute_css = {
code = [[
(call
function: (attribute
attribute: (identifier) @_idd (#eq? @_idd "style"))
arguments: (argument_list
(string (string_content) @injection.content (#set! injection.language "css"))))
]],
description = "CSS syntax in all strings in call expressions that are methods named 'style'",
},
loads_attribute_json = {
code = [[
(call
function: (attribute
attribute: (identifier) @_idd (#eq? @_idd "loads"))
arguments: (argument_list
(string (string_content) @injection.content (#set! injection.language "json") ) ) )
]],
description = "JSON syntax in all strings in call expressions that are method calls named 'loads'",
},
r_in_tagged_strings = {
code = [[
(string
(string_content) @injection.content
(#vim-match? @injection.content "#R")
(#set! injection.language "r")
)
]],
description = "R syntax in all strings that contain #R",
},
},
}
for lang, _ in pairs(preset_injections) do
for k, _ in pairs(preset_injections[lang]) do
preset_injections[lang][k]["standard_or_custom"] = "custom"
preset_injections[lang][k]["order"] = 0
preset_injections[lang][k]["enabled"] = false
preset_injections[lang][k]["sourcelang"] = lang
end
end
return preset_injections