Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ea7601

Browse files
author
fidgetingbits
committedNov 3, 2023
Fix call argument handling and support inherit keyword
1 parent 7136a10 commit 9ea7601

File tree

16 files changed

+569
-2
lines changed

16 files changed

+569
-2
lines changed
 
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
{
16+
outputs = { self, nixpkgs, home-manager }:
17+
"foo"
18+
}
19+
selections:
20+
- anchor: {line: 1, character: 13}
21+
active: {line: 1, character: 13}
22+
marks: {}
23+
finalState:
24+
documentContents: |-
25+
{
26+
outputs = :
27+
"foo"
28+
}
29+
selections:
30+
- anchor: {line: 1, character: 12}
31+
active: {line: 1, character: 12}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 35}
20+
active: {line: 1, character: 35}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = mkFunc "a" "b" d e;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 33}
29+
active: {line: 1, character: 33}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a";
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 26}
20+
active: {line: 1, character: 26}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = mkFunc ;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 25}
29+
active: {line: 1, character: 25}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change arg pit
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: p}
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: argumentOrParameter}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |
16+
{
17+
inherit pkgs input output;
18+
}
19+
selections:
20+
- anchor: {line: 1, character: 17}
21+
active: {line: 1, character: 17}
22+
marks:
23+
default.p:
24+
start: {line: 1, character: 10}
25+
end: {line: 1, character: 14}
26+
finalState:
27+
documentContents: |
28+
{
29+
inherit input output;
30+
}
31+
selections:
32+
- anchor: {line: 1, character: 10}
33+
active: {line: 1, character: 10}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change call
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCall}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 25}
20+
active: {line: 1, character: 25}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = ;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 28}
20+
active: {line: 1, character: 28}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = "a" "b" "c" d e;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 32}
20+
active: {line: 1, character: 32}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = "a" "b" "c" d e;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 36}
20+
active: {line: 1, character: 36}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = "a" "b" "c" d e;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 38}
20+
active: {line: 1, character: 38}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = "a" "b" "c" d e;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 40}
20+
active: {line: 1, character: 40}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = "a" "b" "c" d e;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a";
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 26}
20+
active: {line: 1, character: 26}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = "a";
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 18}
29+
active: {line: 1, character: 18}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
inherit pkgs input output;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 17}
20+
active: {line: 1, character: 17}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
pkgs input output;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 2}
29+
active: {line: 1, character: 2}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change every arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: everyScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
exampleHost = mkFunc "a" "b" "c" d e;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 35}
20+
active: {line: 1, character: 35}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
exampleHost = mkFunc ;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 25}
29+
active: {line: 1, character: 25}
30+
- anchor: {line: 1, character: 26}
31+
active: {line: 1, character: 26}
32+
- anchor: {line: 1, character: 27}
33+
active: {line: 1, character: 27}
34+
- anchor: {line: 1, character: 28}
35+
active: {line: 1, character: 28}
36+
- anchor: {line: 1, character: 29}
37+
active: {line: 1, character: 29}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: change every arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: everyScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
inherit pkgs input output;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 17}
20+
active: {line: 1, character: 17}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
inherit ;
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 10}
29+
active: {line: 1, character: 10}
30+
- anchor: {line: 1, character: 11}
31+
active: {line: 1, character: 11}
32+
- anchor: {line: 1, character: 12}
33+
active: {line: 1, character: 12}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: nix
2+
command:
3+
version: 6
4+
spokenForm: chuck call
5+
action:
6+
name: remove
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCall}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
{
16+
inherit pkgs input output;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 17}
20+
active: {line: 1, character: 17}
21+
marks: {}
22+
finalState:
23+
documentContents: |
24+
{
25+
26+
}
27+
selections:
28+
- anchor: {line: 1, character: 0}
29+
active: {line: 1, character: 0}

‎queries/nix.scm

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
;;
12
;; Statements
3+
;;
24

35
;; Any top-level expression that isn't a comment is a statement
46
(
@@ -51,7 +53,9 @@
5153
(_) @statement.iteration @value.iteration @name.iteration
5254
)
5355

56+
;;
5457
;; Conditionals
58+
;;
5559

5660
;;!! key = if a then b else c;
5761
;;! ^^^^^^^^^^^^^^^^^^
@@ -79,7 +83,9 @@
7983
condition: (_) @condition
8084
) @_.domain
8185

86+
;;
8287
;; Lists and maps
88+
;;
8389

8490
;;!! foo = [ a b c ];
8591
;;! ^^^^^^^^^
@@ -103,7 +109,9 @@
103109
expression: (_) @_.trailing.end.startOf
104110
) @_.domain
105111

112+
;;
106113
;; Strings
114+
;;
107115

108116
;;!! # foo
109117
;;! ^^^^^
@@ -122,7 +130,9 @@
122130
(interpolation) @argumentOrParameter
123131
) @_.iteration
124132

133+
;;
125134
;; Functions
135+
;;
126136

127137
;; Note for this part of the function, we identify is as lambda only
128138
;;!! x = a: b: a + b;
@@ -154,17 +164,121 @@
154164
expression: (function_expression) @namedFunction.interior
155165
) @namedFunction @functionName.domain
156166

167+
;; Calls to functions are a bit finicky, because of everything being curried lambdas
168+
(
169+
(apply_expression) @dummy @functionCall @argumentOrParameter.iteration
170+
(#not-parent-type? @functionCall apply_expression)
171+
)
172+
173+
;; This is gross, but not sure how to do fuzzy matching against an unknown number of
174+
;; nested child nodes. Arbitrarily stopping at 5 args for now, as that ought to be enough
175+
;; arguments for anyone
176+
;; Args:
177+
;;!! mkHost a b c d e
178+
;;! ^
179+
;;! xx
180+
;;! <*********>
181+
;;! Callee:
182+
;;!! mkHost a b c d e
183+
;;! ^^^^^^
184+
;;! xxxxxxx
185+
;;! ----------------
186+
;; The mkHost node looks like this:
187+
;; # (binding_set
188+
;; # binding: (binding
189+
;; # expression: (attrset_expression
190+
;; # (binding_set
191+
;; # binding: (binding
192+
;; # expression: (apply_expression
193+
;; # function: (apply_expression
194+
;; # function: (apply_expression
195+
;; # function: (variable_expression
196+
;; # name: (identifier)
197+
;; # )
198+
(apply_expression
199+
[
200+
(apply_expression
201+
function: (variable_expression
202+
name: (identifier) @functionCallee
203+
)
204+
)
205+
(apply_expression
206+
[
207+
(apply_expression
208+
function: (variable_expression
209+
name: (identifier) @functionCallee
210+
)
211+
)
212+
(apply_expression
213+
[
214+
(apply_expression
215+
function: (variable_expression
216+
name: (identifier) @functionCallee
217+
)
218+
)
219+
(apply_expression
220+
(apply_expression
221+
function: (variable_expression
222+
name: (identifier) @functionCallee
223+
)
224+
)
225+
)
226+
]
227+
)
228+
]
229+
)
230+
]
231+
) @_.domain
232+
233+
;; Args:
234+
;;!! mkHost a
235+
;;! ^
236+
;;! x
237+
;;! --------
238+
;;! Callee:
239+
;;!! mkHost a
240+
;;! ^^^^^^
241+
;;! xxxxxx
242+
;;! --------
157243
(apply_expression
158-
function: (_) @functionCallee
244+
function: (variable_expression
245+
name: (identifier) @functionCallee
246+
)
159247
argument: (_) @argumentOrParameter
160248
) @_.domain
161249

162-
(apply_expression) @functionCall
250+
(apply_expression
251+
argument: (_) @argumentOrParameter
252+
)
253+
163254
(function_expression
164255
(formals) @argumentOrParameter
165256
) @_.domain
166257

258+
;; inherit is a built-in keyword, but is close enough to a function...
259+
;; Callee:
260+
;;!! inherit pkgs input output;
261+
;;! ^^^^^^^
262+
;;! xxxxxxxx
263+
;;! -------------------------
264+
;; Args:
265+
;;!! inherit pkgs input output;
266+
;;! ^^^^
267+
;;! xxxxx
268+
;;! <*****************>
269+
(inherit
270+
"inherit" @functionCallee
271+
(
272+
(inherited_attrs) @argumentOrParameter.iteration
273+
)
274+
) @functionCall @_.domain
275+
(inherited_attrs
276+
attr: (_) @argumentOrParameter
277+
)
278+
279+
;;
167280
;; Names and Values
281+
;;
168282

169283
;;!! a = 25;
170284
;;! ^^

0 commit comments

Comments
 (0)
Please sign in to comment.