on master help sign in
queries/nix: add injections for builtins and writers (#5629)
commit22b3d3d6367f2e559a7193172bd1dba03b864bd3 authorpacien <pacien@users.noreply.github.com> dateWed 25 Jan 2023, 23:44 (4 years ago) parent2db8796
1 file changed+110
runtime/queries/nix/injections.scm+110
runtime/queries/nix/injections.scm+110
@@ -6,6 +6,8 @@
66 (indented_string_expression (string_fragment) @injection.content))
77 (#set! injection.combined))
88
9+; Common attribute keys corresponding to scripts,
10+; such as those of stdenv.mkDerivation.
911((binding
1012 attrpath: (attrpath (identifier) @_path)
1113 expression: (indented_string_expression
@@ -14,6 +16,25 @@
1416 (#set! injection.language "bash")
1517 (#set! injection.combined))
1618
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
1738((apply_expression
1839 function: (apply_expression function: (_) @_func)
1940 argument: (indented_string_expression (string_fragment) @injection.content))
@@ -21,6 +42,8 @@
2142 (#set! injection.language "bash")
2243 (#set! injection.combined))
2344
45+; trivial-builders.nix, aliases.nix
46+; pkgs.runCommand[[No]CC][Local] name attrs content
2447(apply_expression
2548 (apply_expression
2649 function: (apply_expression
@@ -30,6 +53,7 @@
3053 (#set! injection.language "bash")
3154 (#set! injection.combined))
3255
56+; trivial-builders.nix pkgs.writeShellApplication { text = content; }
3357(apply_expression
3458 function: ((_) @_func)
3559 argument: (_ (_)* (_ (_)* (binding
@@ -40,3 +64,89 @@
4064 (#match? @_path "^text$")
4165 (#set! injection.language "bash")
4266 (#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))