Skip to content

Commit 4a2091e

Browse files
authored
Support "name" and "value" in guard of Python for-each statements (#1919)
- Depends on #1922, which migrates `"name"` in Python - Depends on #1924, which migrates `value` in Typescript ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet
1 parent 6230ecb commit 4a2091e

File tree

10 files changed

+208
-0
lines changed

10 files changed

+208
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: javascript
2+
command:
3+
version: 6
4+
spokenForm: change name
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: name}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: for (const aaa of bbb) {}
15+
selections:
16+
- anchor: {line: 0, character: 0}
17+
active: {line: 0, character: 0}
18+
marks: {}
19+
finalState:
20+
documentContents: for (const of bbb) {}
21+
selections:
22+
- anchor: {line: 0, character: 11}
23+
active: {line: 0, character: 11}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
languageId: javascript
2+
command:
3+
version: 6
4+
spokenForm: change name
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: name}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: for (const aaa of bbb) {}
15+
selections:
16+
- anchor: {line: 0, character: 24}
17+
active: {line: 0, character: 24}
18+
marks: {}
19+
thrownError: {name: NoContainingScopeError}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: javascript
2+
command:
3+
version: 6
4+
spokenForm: change value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: value}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: for (const aaa of bbb) {}
15+
selections:
16+
- anchor: {line: 0, character: 0}
17+
active: {line: 0, character: 0}
18+
marks: {}
19+
finalState:
20+
documentContents: for (const aaa of ) {}
21+
selections:
22+
- anchor: {line: 0, character: 18}
23+
active: {line: 0, character: 18}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
languageId: javascript
2+
command:
3+
version: 6
4+
spokenForm: change value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: value}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: for (const aaa of bbb) {}
15+
selections:
16+
- anchor: {line: 0, character: 24}
17+
active: {line: 0, character: 24}
18+
marks: {}
19+
thrownError: {name: NoContainingScopeError}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: python
2+
command:
3+
version: 6
4+
spokenForm: change name
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: name}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
for aaa in bbb:
16+
pass
17+
selections:
18+
- anchor: {line: 0, character: 0}
19+
active: {line: 0, character: 0}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
for in bbb:
24+
pass
25+
selections:
26+
- anchor: {line: 0, character: 4}
27+
active: {line: 0, character: 4}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
languageId: python
2+
command:
3+
version: 6
4+
spokenForm: change name
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: name}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
for aaa in bbb:
16+
pass
17+
selections:
18+
- anchor: {line: 1, character: 4}
19+
active: {line: 1, character: 4}
20+
marks: {}
21+
thrownError: {name: NoContainingScopeError}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: python
2+
command:
3+
version: 6
4+
spokenForm: change value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: value}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
for aaa in bbb:
16+
pass
17+
selections:
18+
- anchor: {line: 0, character: 0}
19+
active: {line: 0, character: 0}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
for aaa in :
24+
pass
25+
selections:
26+
- anchor: {line: 0, character: 11}
27+
active: {line: 0, character: 11}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
languageId: python
2+
command:
3+
version: 6
4+
spokenForm: change value
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: value}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
for aaa in bbb:
16+
pass
17+
selections:
18+
- anchor: {line: 1, character: 4}
19+
active: {line: 1, character: 4}
20+
marks: {}
21+
thrownError: {name: NoContainingScopeError}

queries/javascript.core.scm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,20 @@
310310
(_) @value
311311
) @_.domain
312312

313+
;; name:
314+
;;!! for (const aaa of bbb) {}
315+
;;! ^^^
316+
;;! ----------------------
317+
;; value:
318+
;;!! for (const aaa of bbb) {}
319+
;;! ^^^
320+
;;! ----------------------
321+
(for_in_statement
322+
left: (_) @name
323+
right: (_) @value
324+
")" @_.domain.end.endOf
325+
) @_.domain.start.startOf
326+
313327
[
314328
(program)
315329
(formal_parameters)

queries/python.scm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@
140140
(_) @value
141141
) @_.domain
142142

143+
;; value:
144+
;;!! for aaa in bbb:
145+
;;! ^^^
146+
;;! ---------------
147+
;; name:
148+
;;!! for aaa in bbb:
149+
;;! ^^^
150+
;;! ---------------
151+
(for_statement
152+
left: (_) @name
153+
right: (_) @value
154+
":" @_.domain.end
155+
) @_.domain.start.startOf
156+
143157
(comment) @comment @textFragment
144158

145159
(string

0 commit comments

Comments
 (0)