Skip to content

Commit

Permalink
Support "name" and "value" in guard of Python for-each statements (cu…
Browse files Browse the repository at this point in the history
…rsorless-dev#1919)

- Depends on cursorless-dev#1922,
which migrates `"name"` in Python
- Depends on cursorless-dev#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
  • Loading branch information
pokey authored Oct 3, 2023
1 parent 6230ecb commit 4a2091e
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: javascript
command:
version: 6
spokenForm: change name
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: for (const aaa of bbb) {}
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: for (const of bbb) {}
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
languageId: javascript
command:
version: 6
spokenForm: change name
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: for (const aaa of bbb) {}
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
marks: {}
thrownError: {name: NoContainingScopeError}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
languageId: javascript
command:
version: 6
spokenForm: change value
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: value}
usePrePhraseSnapshot: true
initialState:
documentContents: for (const aaa of bbb) {}
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: for (const aaa of ) {}
selections:
- anchor: {line: 0, character: 18}
active: {line: 0, character: 18}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
languageId: javascript
command:
version: 6
spokenForm: change value
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: value}
usePrePhraseSnapshot: true
initialState:
documentContents: for (const aaa of bbb) {}
selections:
- anchor: {line: 0, character: 24}
active: {line: 0, character: 24}
marks: {}
thrownError: {name: NoContainingScopeError}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: python
command:
version: 6
spokenForm: change name
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
for aaa in bbb:
pass
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: |-
for in bbb:
pass
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
languageId: python
command:
version: 6
spokenForm: change name
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: name}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
for aaa in bbb:
pass
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
thrownError: {name: NoContainingScopeError}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: python
command:
version: 6
spokenForm: change value
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: value}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
for aaa in bbb:
pass
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: |-
for aaa in :
pass
selections:
- anchor: {line: 0, character: 11}
active: {line: 0, character: 11}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
languageId: python
command:
version: 6
spokenForm: change value
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: value}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
for aaa in bbb:
pass
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
thrownError: {name: NoContainingScopeError}
14 changes: 14 additions & 0 deletions queries/javascript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@
(_) @value
) @_.domain

;; name:
;;!! for (const aaa of bbb) {}
;;! ^^^
;;! ----------------------
;; value:
;;!! for (const aaa of bbb) {}
;;! ^^^
;;! ----------------------
(for_in_statement
left: (_) @name
right: (_) @value
")" @_.domain.end.endOf
) @_.domain.start.startOf

[
(program)
(formal_parameters)
Expand Down
14 changes: 14 additions & 0 deletions queries/python.scm
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@
(_) @value
) @_.domain

;; value:
;;!! for aaa in bbb:
;;! ^^^
;;! ---------------
;; name:
;;!! for aaa in bbb:
;;! ^^^
;;! ---------------
(for_statement
left: (_) @name
right: (_) @value
":" @_.domain.end
) @_.domain.start.startOf

(comment) @comment @textFragment

(string
Expand Down

0 comments on commit 4a2091e

Please sign in to comment.