on master help sign in
queries/nix: add injections for builtins and writers (#5629)
22b3d3dpacien
runtime/queries/nix/injections.scm+110
@@ -6,6 +6,8 @@
6 (indented_string_expression (string_fragment) @injection.content))
6 (indented_string_expression (string_fragment) @injection.content))
7 (#set! injection.combined))
7 (#set! injection.combined))
8
8
9+; Common attribute keys corresponding to scripts,
10+; such as those of stdenv.mkDerivation.
9((binding
11((binding
10 attrpath: (attrpath (identifier) @_path)
12 attrpath: (attrpath (identifier) @_path)
11 expression: (indented_string_expression
13 expression: (indented_string_expression
@@ -14,6 +16,25 @@
14 (#set! injection.language "bash")
16 (#set! injection.language "bash")
15 (#set! injection.combined))
17 (#set! injection.combined))
16
18
19+; builtins.{match,split} regex str
20+; Example: nix/tests/lang/eval-okay-regex-{match,split}.nix
21+((apply_expression
22+ function: (_) @_func
23+ argument: (indented_string_expression (string_fragment) @injection.content))
24+ (#match? @_func "(^|\\.)match|split$")
25+ (#set! injection.language "regex")
26+ (#set! injection.combined))
27+
28+; builtins.fromJSON json
29+; Example: nix/tests/lang/eval-okay-fromjson.nix
30+((apply_expression
31+ function: (_) @_func
32+ argument: (indented_string_expression (string_fragment) @injection.content))
33+ (#match? @_func "(^|\\.)fromJSON$")
34+ (#set! injection.language "json")
35+ (#set! injection.combined))
36+
37+; trivial-builders.nix pkgs.writeShellScript[Bin] name content
17((apply_expression
38((apply_expression
18 function: (apply_expression function: (_) @_func)
39 function: (apply_expression function: (_) @_func)
19 argument: (indented_string_expression (string_fragment) @injection.content))
40 argument: (indented_string_expression (string_fragment) @injection.content))
@@ -21,6 +42,8 @@
21 (#set! injection.language "bash")
42 (#set! injection.language "bash")
22 (#set! injection.combined))
43 (#set! injection.combined))
23
44
45+; trivial-builders.nix, aliases.nix
46+; pkgs.runCommand[[No]CC][Local] name attrs content
24(apply_expression
47(apply_expression
25 (apply_expression
48 (apply_expression
26 function: (apply_expression
49 function: (apply_expression
@@ -30,6 +53,7 @@
30 (#set! injection.language "bash")
53 (#set! injection.language "bash")
31 (#set! injection.combined))
54 (#set! injection.combined))
32
55
56+; trivial-builders.nix pkgs.writeShellApplication { text = content; }
33(apply_expression
57(apply_expression
34 function: ((_) @_func)
58 function: ((_) @_func)
35 argument: (_ (_)* (_ (_)* (binding
59 argument: (_ (_)* (_ (_)* (binding
@@ -40,3 +64,89 @@
40 (#match? @_path "^text$")
64 (#match? @_path "^text$")
41 (#set! injection.language "bash")
65 (#set! injection.language "bash")
42 (#set! injection.combined))
66 (#set! injection.combined))
67+
68+; trivial-builders.nix pkgs.writeCBin name content
69+((apply_expression
70+ function: (apply_expression function: (_) @_func)
71+ argument: (indented_string_expression (string_fragment) @injection.content))
72+ (#match? @_func "(^|\\.)writeC(Bin)?$")
73+ (#set! injection.language "c")
74+ (#set! injection.combined))
75+
76+; pkgs.writers.* usage examples: nixpkgs/pkgs/build-support/writers/test.nix
77+
78+; pkgs.writers.write{Bash,Dash}[Bin] name content
79+((apply_expression
80+ function: (apply_expression function: (_) @_func)
81+ argument: (indented_string_expression (string_fragment) @injection.content))
82+ (#match? @_func "(^|\\.)write[BD]ash(Bin)?$")
83+ (#set! injection.language "bash")
84+ (#set! injection.combined))
85+
86+; pkgs.writers.writeFish[Bin] name content
87+((apply_expression
88+ function: (apply_expression function: (_) @_func)
89+ argument: (indented_string_expression (string_fragment) @injection.content))
90+ (#match? @_func "(^|\\.)writeFish(Bin)?$")
91+ (#set! injection.language "fish")
92+ (#set! injection.combined))
93+
94+; pkgs.writers.writeRust[Bin] name attrs content
95+(apply_expression
96+ (apply_expression
97+ function: (apply_expression
98+ function: ((_) @_func)))
99+ argument: (indented_string_expression (string_fragment) @injection.content)
100+ (#match? @_func "(^|\\.)writeRust(Bin)?$")
101+ (#set! injection.language "rust")
102+ (#set! injection.combined))
103+
104+; pkgs.writers.writeHaskell[Bin] name attrs content
105+(apply_expression
106+ (apply_expression
107+ function: (apply_expression
108+ function: ((_) @_func)))
109+ argument: (indented_string_expression (string_fragment) @injection.content)
110+ (#match? @_func "(^|\\.)writeHaskell(Bin)?$")
111+ (#set! injection.language "haskell")
112+ (#set! injection.combined))
113+
114+; pkgs.writers.writeJS[Bin] name attrs content
115+(apply_expression
116+ (apply_expression
117+ function: (apply_expression
118+ function: ((_) @_func)))
119+ argument: (indented_string_expression (string_fragment) @injection.content)
120+ (#match? @_func "(^|\\.)writeJS(Bin)?$")
121+ (#set! injection.language "javascript")
122+ (#set! injection.combined))
123+
124+; pkgs.writers.writePerl[Bin] name attrs content
125+(apply_expression
126+ (apply_expression
127+ function: (apply_expression
128+ function: ((_) @_func)))
129+ argument: (indented_string_expression (string_fragment) @injection.content)
130+ (#match? @_func "(^|\\.)writePerl(Bin)?$")
131+ (#set! injection.language "perl")
132+ (#set! injection.combined))
133+
134+; pkgs.writers.write{Python,PyPy}{2,3}[Bin] name attrs content
135+(apply_expression
136+ (apply_expression
137+ function: (apply_expression
138+ function: ((_) @_func)))
139+ argument: (indented_string_expression (string_fragment) @injection.content)
140+ (#match? @_func "(^|\\.)write(Python|PyPy)[23](Bin)?$")
141+ (#set! injection.language "python")
142+ (#set! injection.combined))
143+
144+; pkgs.writers.writeFSharp[Bin] name content
145+; No query available for f-sharp as of the time of writing
146+; See: https://github.com/helix-editor/helix/issues/4943
147+; ((apply_expression
148+; function: (apply_expression function: (_) @_func)
149+; argument: (indented_string_expression (string_fragment) @injection.content))
150+; (#match? @_func "(^|\\.)writeFSharp(Bin)?$")
151+; (#set! injection.language "f-sharp")
152+; (#set! injection.combined))