injections.scm

  1; Refer to https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/go/injections.scm#L4C1-L16C41
  2((comment) @injection.content
  3 (#set! injection.language "comment")
  4)
  5
  6(call_expression
  7  (selector_expression) @_function
  8  (#any-of? @_function
  9    "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX"
 10    "regexp.MustCompile" "regexp.MustCompilePOSIX")
 11  (argument_list
 12    .
 13    [
 14      (raw_string_literal)
 15      (interpreted_string_literal)
 16    ] @injection.content
 17    (#set! injection.language "regex")
 18    ))
 19
 20; INJECT SQL
 21(
 22	[
 23		; var, const or short declaration of raw or interpreted string literal
 24		((comment) @comment
 25  		.
 26    	(expression_list
 27     	[
 28      		(interpreted_string_literal)
 29        	(raw_string_literal)
 30        ] @injection.content
 31        ))
 32
 33        ; when passing as a literal element (to struct field eg.)
 34		((comment) @comment
 35        .
 36        (literal_element
 37        [
 38        	(interpreted_string_literal)
 39        	(raw_string_literal)
 40        ] @injection.content
 41        ))
 42
 43        ; when passing as a function parameter
 44        ((comment) @comment
 45        .
 46        [
 47        	(interpreted_string_literal)
 48        	(raw_string_literal)
 49        ] @injection.content)
 50    ]
 51
 52    (#match? @comment "^\\/\\*\\s*sql\\s*\\*\\/") ; /* sql */ or /*sql*/
 53    (#set! injection.language "sql")
 54)
 55
 56; INJECT JSON
 57(
 58	[
 59		; var, const or short declaration of raw or interpreted string literal
 60		((comment) @comment
 61  		.
 62    	(expression_list
 63     	[
 64      		(interpreted_string_literal)
 65        	(raw_string_literal)
 66        ] @injection.content
 67        ))
 68
 69        ; when passing as a literal element (to struct field eg.)
 70		((comment) @comment
 71        .
 72        (literal_element
 73        [
 74        	(interpreted_string_literal)
 75        	(raw_string_literal)
 76        ] @injection.content
 77        ))
 78
 79        ; when passing as a function parameter
 80        ((comment) @comment
 81        .
 82        [
 83        	(interpreted_string_literal)
 84        	(raw_string_literal)
 85        ] @injection.content)
 86    ]
 87
 88    (#match? @comment "^\\/\\*\\s*json\\s*\\*\\/") ; /* json */ or /*json*/
 89    (#set! injection.language "json")
 90)
 91
 92; INJECT YAML
 93(
 94	[
 95		; var, const or short declaration of raw or interpreted string literal
 96		((comment) @comment
 97  		.
 98    	(expression_list
 99     	[
100      		(interpreted_string_literal)
101        	(raw_string_literal)
102        ] @injection.content
103        ))
104
105        ; when passing as a literal element (to struct field eg.)
106		((comment) @comment
107        .
108        (literal_element
109        [
110        	(interpreted_string_literal)
111        	(raw_string_literal)
112        ] @injection.content
113        ))
114
115        ; when passing as a function parameter
116        ((comment) @comment
117        .
118        [
119        	(interpreted_string_literal)
120        	(raw_string_literal)
121        ] @injection.content)
122    ]
123
124    (#match? @comment "^\\/\\*\\s*yaml\\s*\\*\\/") ; /* yaml */ or /*yaml*/
125    (#set! injection.language "yaml")
126)
127
128; INJECT XML
129(
130	[
131		; var, const or short declaration of raw or interpreted string literal
132		((comment) @comment
133  		.
134    	(expression_list
135     	[
136      		(interpreted_string_literal)
137        	(raw_string_literal)
138        ] @injection.content
139        ))
140
141        ; when passing as a literal element (to struct field eg.)
142		((comment) @comment
143        .
144        (literal_element
145        [
146        	(interpreted_string_literal)
147        	(raw_string_literal)
148        ] @injection.content
149        ))
150
151        ; when passing as a function parameter
152        ((comment) @comment
153        .
154        [
155        	(interpreted_string_literal)
156        	(raw_string_literal)
157        ] @injection.content)
158    ]
159
160    (#match? @comment "^\\/\\*\\s*xml\\s*\\*\\/") ; /* xml */ or /*xml*/
161    (#set! injection.language "xml")
162)
163
164; INJECT HTML
165(
166	[
167		; var, const or short declaration of raw or interpreted string literal
168		((comment) @comment
169  		.
170    	(expression_list
171     	[
172      		(interpreted_string_literal)
173        	(raw_string_literal)
174        ] @injection.content
175        ))
176
177        ; when passing as a literal element (to struct field eg.)
178		((comment) @comment
179        .
180        (literal_element
181        [
182        	(interpreted_string_literal)
183        	(raw_string_literal)
184        ] @injection.content
185        ))
186
187        ; when passing as a function parameter
188        ((comment) @comment
189        .
190        [
191        	(interpreted_string_literal)
192        	(raw_string_literal)
193        ] @injection.content)
194    ]
195
196    (#match? @comment "^\\/\\*\\s*html\\s*\\*\\/") ; /* html */ or /*html*/
197    (#set! injection.language "html")
198)
199
200; INJECT JS
201(
202	[
203		; var, const or short declaration of raw or interpreted string literal
204		((comment) @comment
205  		.
206    	(expression_list
207     	[
208      		(interpreted_string_literal)
209        	(raw_string_literal)
210        ] @injection.content
211        ))
212
213        ; when passing as a literal element (to struct field eg.)
214		((comment) @comment
215        .
216        (literal_element
217        [
218        	(interpreted_string_literal)
219        	(raw_string_literal)
220        ] @injection.content
221        ))
222
223        ; when passing as a function parameter
224        ((comment) @comment
225        .
226        [
227        	(interpreted_string_literal)
228        	(raw_string_literal)
229        ] @injection.content)
230    ]
231
232    (#match? @comment "^\\/\\*\\s*js\\s*\\*\\/") ; /* js */ or /*js*/
233    (#set! injection.language "javascript")
234)
235
236; INJECT CSS
237(
238	[
239		; var, const or short declaration of raw or interpreted string literal
240		((comment) @comment
241  		.
242    	(expression_list
243     	[
244      		(interpreted_string_literal)
245        	(raw_string_literal)
246        ] @injection.content
247        ))
248
249        ; when passing as a literal element (to struct field eg.)
250		((comment) @comment
251        .
252        (literal_element
253        [
254        	(interpreted_string_literal)
255        	(raw_string_literal)
256        ] @injection.content
257        ))
258
259        ; when passing as a function parameter
260        ((comment) @comment
261        .
262        [
263        	(interpreted_string_literal)
264        	(raw_string_literal)
265        ] @injection.content)
266    ]
267
268    (#match? @comment "^\\/\\*\\s*css\\s*\\*\\/") ; /* css */ or /*css*/
269    (#set! injection.language "css")
270)
271
272; INJECT LUA
273(
274	[
275		; var, const or short declaration of raw or interpreted string literal
276		((comment) @comment
277  		.
278    	(expression_list
279     	[
280      		(interpreted_string_literal)
281        	(raw_string_literal)
282        ] @injection.content
283        ))
284
285        ; when passing as a literal element (to struct field eg.)
286		((comment) @comment
287        .
288        (literal_element
289        [
290        	(interpreted_string_literal)
291        	(raw_string_literal)
292        ] @injection.content
293        ))
294
295        ; when passing as a function parameter
296        ((comment) @comment
297        .
298        [
299        	(interpreted_string_literal)
300        	(raw_string_literal)
301        ] @injection.content)
302    ]
303
304    (#match? @comment "^\\/\\*\\s*lua\\s*\\*\\/") ; /* lua */ or /*lua*/
305    (#set! injection.language "lua")
306)
307
308; INJECT BASH
309(
310	[
311		; var, const or short declaration of raw or interpreted string literal
312		((comment) @comment
313  		.
314    	(expression_list
315     	[
316      		(interpreted_string_literal)
317        	(raw_string_literal)
318        ] @injection.content
319        ))
320
321        ; when passing as a literal element (to struct field eg.)
322		((comment) @comment
323        .
324        (literal_element
325        [
326        	(interpreted_string_literal)
327        	(raw_string_literal)
328        ] @injection.content
329        ))
330
331        ; when passing as a function parameter
332        ((comment) @comment
333        .
334        [
335        	(interpreted_string_literal)
336        	(raw_string_literal)
337        ] @injection.content)
338    ]
339
340    (#match? @comment "^\\/\\*\\s*bash\\s*\\*\\/") ; /* bash */ or /*bash*/
341    (#set! injection.language "bash")
342)
343
344; INJECT CSV
345(
346	[
347		; var, const or short declaration of raw or interpreted string literal
348		((comment) @comment
349  		.
350    	(expression_list
351     	[
352      		(interpreted_string_literal)
353        	(raw_string_literal)
354        ] @injection.content
355        ))
356
357        ; when passing as a literal element (to struct field eg.)
358		((comment) @comment
359        .
360        (literal_element
361        [
362        	(interpreted_string_literal)
363        	(raw_string_literal)
364        ] @injection.content
365        ))
366
367        ; when passing as a function parameter
368        ((comment) @comment
369        .
370        [
371        	(interpreted_string_literal)
372        	(raw_string_literal)
373        ] @injection.content)
374    ]
375
376    (#match? @comment "^\\/\\*\\s*csv\\s*\\*\\/") ; /* csv */ or /*csv*/
377    (#set! injection.language "csv")
378)