Skip to content

Commit 665e27f

Browse files
nrdxpthe-mikedavis
authored andcommitted
nix: add language injections
By simply placing a comment with the name of the desired language just before a multi-line string, that language will be injected. Also, common functions and attributes which are expected to be shell code are automatically injected.
1 parent 43b31f7 commit 665e27f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

runtime/queries/nix/injections.scm

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; mark arbitary languages with a comment
2+
((((comment) @injection.language) .
3+
(indented_string_expression (string_fragment) @injection.content))
4+
(#set! injection.combined))
5+
6+
((binding
7+
attrpath: (attrpath (identifier) @_path)
8+
expression: (indented_string_expression
9+
(string_fragment) @injection.content))
10+
(#match? @_path "(^\\w*Phase|(pre|post)\\w*|(.*\\.)?\\w*([sS]cript|[hH]ook)|(.*\\.)?startup)$")
11+
(#set! injection.language "bash")
12+
(#set! injection.combined))
13+
14+
((apply_expression
15+
function: (apply_expression function: (_) @_func)
16+
argument: (indented_string_expression (string_fragment) @injection.content))
17+
(#match? @_func "(^|\\.)writeShellScript(Bin)?$")
18+
(#set! injection.language "bash")
19+
(#set! injection.combined))
20+
21+
(apply_expression
22+
(apply_expression
23+
function: (apply_expression
24+
function: ((_) @_func)))
25+
argument: (indented_string_expression (string_fragment) @injection.content)
26+
(#match? @_func "(^|\\.)runCommand(((No)?(CC))?(Local)?)?$")
27+
(#set! injection.language "bash")
28+
(#set! injection.combined))
29+
30+
(apply_expression
31+
function: ((_) @_func)
32+
argument: (_ (_)* (_ (_)* (binding
33+
attrpath: (attrpath (identifier) @_path)
34+
expression: (indented_string_expression
35+
(string_fragment) @injection.content))))
36+
(#match? @_func "(^|\\.)writeShellApplication$")
37+
(#match? @_path "^text$")
38+
(#set! injection.language "bash")
39+
(#set! injection.combined))

0 commit comments

Comments
 (0)