Skip to content

Commit 21d78d5

Browse files
Added scope type for "inside" (#2776)
Inside/interior today is a modifier and will stay so in the future, but we are also introducing interior as a scope type. This will allow us to do `"take inside"` when on a if statement, python function and so on. It now takes the closest of the nearest tree-sitter interior _or_ surrounding pair. This is most useful for Python; in other languages with {} statement-blocks, the braces would already be easy to target, but now "take inside" behaves intuitively there as well. The scm syntax `@scope.interior` have been replaced by `@interior` as its own scope type. Fixes #1046 ## Checklist - [x] 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 ## Release notes You can now use "inside" to refer to the inside body of a language scope (function, if statement, etc). This is especially useful for Python, because previously you had to think about what scope you were targeting -- "take inside" now just works. It also works nicely for targeting the inside of C-style statements that don't have `{}` braces, like single line conditionals or loops. In Python, this also means that you can now target the inside of the function ("take inside") even while the cursor is in a related location (such as in its name). Note that this behavior currently only exists for Python; we plan to port it to other languages as well since it is useful. --------- Co-authored-by: Phil Cohen <[email protected]>
1 parent 6ea80b5 commit 21d78d5

File tree

69 files changed

+942
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+942
-251
lines changed

cursorless-talon/src/spoken_forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
161161
"textFragment",
162162
"disqualifyDelimiter",
163163
"pairDelimiter",
164+
"interior",
164165
],
165166
default_list_name="scope_type",
166167
),

data/fixtures/recorded/implicitExpansion/clearCoreToken.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,4 @@ initialState:
1717
- anchor: {line: 0, character: 1}
1818
active: {line: 0, character: 1}
1919
marks: {}
20-
finalState:
21-
documentContents: ()
22-
selections:
23-
- anchor: {line: 0, character: 1}
24-
active: {line: 0, character: 1}
20+
thrownError: {name: NoContainingScopeError}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
languageId: python
2+
command:
3+
version: 7
4+
spokenForm: change inside
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: |-
14+
def testing():
15+
pass
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: |-
22+
def testing():
23+
24+
selections:
25+
- anchor: {line: 1, character: 4}
26+
active: {line: 1, character: 4}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: html
2+
command:
3+
version: 7
4+
spokenForm: change inside
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: <div>content</div>
14+
selections:
15+
- anchor: {line: 0, character: 1}
16+
active: {line: 0, character: 1}
17+
marks: {}
18+
finalState:
19+
documentContents: <>content</div>
20+
selections:
21+
- anchor: {line: 0, character: 1}
22+
active: {line: 0, character: 1}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: html
2+
command:
3+
version: 7
4+
spokenForm: change inside
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: <div>content</div>
14+
selections:
15+
- anchor: {line: 0, character: 9}
16+
active: {line: 0, character: 9}
17+
marks: {}
18+
finalState:
19+
documentContents: <div></div>
20+
selections:
21+
- anchor: {line: 0, character: 5}
22+
active: {line: 0, character: 5}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: change inside
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: (hello)
14+
selections:
15+
- anchor: {line: 0, character: 3}
16+
active: {line: 0, character: 3}
17+
marks: {}
18+
finalState:
19+
documentContents: ()
20+
selections:
21+
- anchor: {line: 0, character: 1}
22+
active: {line: 0, character: 1}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
languageId: html
2+
command:
3+
version: 7
4+
spokenForm: change inside
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
usePrePhraseSnapshot: false
12+
initialState:
13+
documentContents: <div>content</div> (hello)
14+
selections:
15+
- anchor: {line: 0, character: 8}
16+
active: {line: 0, character: 23}
17+
marks: {}
18+
finalState:
19+
documentContents: <div>)
20+
selections:
21+
- anchor: {line: 0, character: 5}
22+
active: {line: 0, character: 5}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
languageId: html
2+
command:
3+
version: 7
4+
spokenForm: change inside element
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
- type: containingScope
12+
scopeType: {type: xmlElement}
13+
usePrePhraseSnapshot: false
14+
initialState:
15+
documentContents: <div>content</div>
16+
selections:
17+
- anchor: {line: 0, character: 1}
18+
active: {line: 0, character: 1}
19+
marks: {}
20+
finalState:
21+
documentContents: <div></div>
22+
selections:
23+
- anchor: {line: 0, character: 5}
24+
active: {line: 0, character: 5}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
<div id="root"></div>
1+
<div id="root">text</div>
22
---
33

44
[Content] =
55
[Removal] =
6-
[Domain] = 0:0-0:21
7-
>---------------------<
8-
0| <div id="root"></div>
9-
10-
[Interior] = 0:15-0:15
11-
><
12-
0| <div id="root"></div>
6+
[Domain] = 0:0-0:25
7+
>-------------------------<
8+
0| <div id="root">text</div>
139

1410
[Insertion delimiter] = "\n"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<div> text </div>
2+
---
3+
4+
[#1 Content] =
5+
[#1 Removal] = 0:1-0:4
6+
>---<
7+
0| <div> text </div>
8+
9+
[#1 Domain] = 0:0-0:5
10+
>-----<
11+
0| <div> text </div>
12+
13+
[#1 Insertion delimiter] = " "
14+
15+
16+
[#2 Content] = 0:6-0:10
17+
>----<
18+
0| <div> text </div>
19+
20+
[#2 Removal] = 0:5-0:11
21+
>------<
22+
0| <div> text </div>
23+
24+
[#2 Domain] = 0:0-0:17
25+
>-----------------<
26+
0| <div> text </div>
27+
28+
[#2 Insertion delimiter] = " "
29+
30+
31+
[#3 Content] =
32+
[#3 Removal] = 0:13-0:16
33+
>---<
34+
0| <div> text </div>
35+
36+
[#3 Domain] = 0:11-0:17
37+
>------<
38+
0| <div> text </div>
39+
40+
[#3 Insertion delimiter] = " "

0 commit comments

Comments
 (0)