on master help sign in
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.

commit665e27ff9dc017ee47f646187d98f5e4cdb18411 authorTimothy DeHerrera <tim@nrdxp.dev> dateSun 28 Aug 2022, 20:16 (4 years ago) parent43b31f7
1 file changed+39
runtime/queries/nix/injections.scm+39
runtime/queries/nix/injections.scmnew file+39
@@ -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))