Skip to content

Commit 09c28c8

Browse files
authored
Add "name" / "value" support for Python with (#2162)
## 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
1 parent d228144 commit 09c28c8

15 files changed

+629
-1
lines changed

packages/common/src/scopeSupportFacets/python.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const { supported, supportedLegacy, notApplicable } = ScopeSupportFacetLevel;
99

1010
export const pythonScopeSupport: LanguageScopeSupportFacetMap = {
1111
"name.foreach": supported,
12+
"name.resource": supported,
13+
"name.resource.iteration": supported,
1214
"value.foreach": supported,
15+
"value.resource": supported,
16+
"value.resource.iteration": supported,
1317

1418
"argument.actual": supportedLegacy,
1519
"argument.actual.iteration": supportedLegacy,

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ export const scopeSupportFacetInfos: Record<
239239
description: "Name (LHS) of a field in a class / interface",
240240
scopeType: "name",
241241
},
242+
"name.resource": {
243+
description: "Name in a 'with' / 'use' / 'using' statement",
244+
scopeType: "name",
245+
},
246+
"name.resource.iteration": {
247+
description:
248+
"Iteration scope for names in a 'with' / 'use' / 'using' statement",
249+
scopeType: "name",
250+
isIteration: true,
251+
},
242252

243253
"key.attribute": {
244254
description: "Key (LHS) of an attribute eg in an xml element",
@@ -289,6 +299,16 @@ export const scopeSupportFacetInfos: Record<
289299
description: "Value (RHS) of a field in a class / interface",
290300
scopeType: "value",
291301
},
302+
"value.resource": {
303+
description: "Value of a 'with' / 'use' / 'using' statement",
304+
scopeType: "value",
305+
},
306+
"value.resource.iteration": {
307+
description:
308+
"Iteration scope for values in a 'with' / 'use' / 'using' statement",
309+
scopeType: "value",
310+
isIteration: true,
311+
},
292312

293313
"type.assignment": {
294314
description: "Type of variable in an assignment",

packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const scopeSupportFacets = [
6363
"name.function",
6464
"name.class",
6565
"name.field",
66+
"name.resource",
67+
"name.resource.iteration",
6668

6769
"key.attribute",
6870
"key.mapPair",
@@ -76,6 +78,8 @@ const scopeSupportFacets = [
7678
"value.return",
7779
"value.return.lambda",
7880
"value.field",
81+
"value.resource",
82+
"value.resource.iteration",
7983

8084
"type.assignment",
8185
"type.formalParameter",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
with aaa, bbb as ccc:
2+
pass
3+
---
4+
5+
[#1 Range] = 0:5-0:20
6+
0| with aaa, bbb as ccc:
7+
>---------------<
8+
9+
[#1 Domain] = 0:0-1:8
10+
0| with aaa, bbb as ccc:
11+
>---------------------
12+
1| pass
13+
--------<
14+
15+
16+
[#2 Range] =
17+
[#2 Domain] = 1:4-1:8
18+
1| pass
19+
>----<
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
with aaa as bbb:
2+
pass
3+
---
4+
5+
[Content] = 0:12-0:15
6+
0| with aaa as bbb:
7+
>---<
8+
9+
[Removal] = 0:8-0:15
10+
0| with aaa as bbb:
11+
>-------<
12+
13+
[Leading delimiter] = 0:8-0:12
14+
0| with aaa as bbb:
15+
>----<
16+
17+
[Domain] = 0:0-1:8
18+
0| with aaa as bbb:
19+
>----------------
20+
1| pass
21+
--------<
22+
23+
[Insertion delimiter] = " "
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
with aaa, bbb as ccc:
2+
pass
3+
---
4+
5+
[#1.1 Content] = 0:5-0:8
6+
0| with aaa, bbb as ccc:
7+
>---<
8+
9+
[#1.1 Removal] = 0:5-0:10
10+
0| with aaa, bbb as ccc:
11+
>-----<
12+
13+
[#1.1 Trailing delimiter] = 0:8-0:10
14+
0| with aaa, bbb as ccc:
15+
>--<
16+
17+
[#1.1 Insertion delimiter] = " "
18+
19+
[#1.2 Content] = 0:17-0:20
20+
0| with aaa, bbb as ccc:
21+
>---<
22+
23+
[#1.2 Removal] = 0:13-0:20
24+
0| with aaa, bbb as ccc:
25+
>-------<
26+
27+
[#1.2 Leading delimiter] = 0:13-0:17
28+
0| with aaa, bbb as ccc:
29+
>----<
30+
31+
[#1.2 Insertion delimiter] = " "
32+
33+
[#1 Domain] = 0:0-1:8
34+
0| with aaa, bbb as ccc:
35+
>---------------------
36+
1| pass
37+
--------<
38+
39+
40+
[#2 Content] =
41+
[#2 Domain] = 0:5-0:8
42+
0| with aaa, bbb as ccc:
43+
>---<
44+
45+
[#2 Removal] = 0:5-0:10
46+
0| with aaa, bbb as ccc:
47+
>-----<
48+
49+
[#2 Trailing delimiter] = 0:8-0:10
50+
0| with aaa, bbb as ccc:
51+
>--<
52+
53+
[#2 Insertion delimiter] = " "
54+
55+
56+
[#3 Content] = 0:17-0:20
57+
0| with aaa, bbb as ccc:
58+
>---<
59+
60+
[#3 Removal] = 0:13-0:20
61+
0| with aaa, bbb as ccc:
62+
>-------<
63+
64+
[#3 Leading delimiter] = 0:13-0:17
65+
0| with aaa, bbb as ccc:
66+
>----<
67+
68+
[#3 Domain] = 0:10-0:20
69+
0| with aaa, bbb as ccc:
70+
>----------<
71+
72+
[#3 Insertion delimiter] = " "
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
with aaa as bbb, ccc as ddd:
2+
pass
3+
---
4+
5+
[#1.1 Content] = 0:12-0:15
6+
0| with aaa as bbb, ccc as ddd:
7+
>---<
8+
9+
[#1.1 Removal] = 0:8-0:15
10+
0| with aaa as bbb, ccc as ddd:
11+
>-------<
12+
13+
[#1.1 Leading delimiter] = 0:8-0:12
14+
0| with aaa as bbb, ccc as ddd:
15+
>----<
16+
17+
[#1.1 Insertion delimiter] = " "
18+
19+
[#1.2 Content] = 0:24-0:27
20+
0| with aaa as bbb, ccc as ddd:
21+
>---<
22+
23+
[#1.2 Removal] = 0:20-0:27
24+
0| with aaa as bbb, ccc as ddd:
25+
>-------<
26+
27+
[#1.2 Leading delimiter] = 0:20-0:24
28+
0| with aaa as bbb, ccc as ddd:
29+
>----<
30+
31+
[#1.2 Insertion delimiter] = " "
32+
33+
[#1 Domain] = 0:0-1:8
34+
0| with aaa as bbb, ccc as ddd:
35+
>----------------------------
36+
1| pass
37+
--------<
38+
39+
40+
[#2 Content] = 0:12-0:15
41+
0| with aaa as bbb, ccc as ddd:
42+
>---<
43+
44+
[#2 Removal] = 0:8-0:15
45+
0| with aaa as bbb, ccc as ddd:
46+
>-------<
47+
48+
[#2 Leading delimiter] = 0:8-0:12
49+
0| with aaa as bbb, ccc as ddd:
50+
>----<
51+
52+
[#2 Domain] = 0:5-0:15
53+
0| with aaa as bbb, ccc as ddd:
54+
>----------<
55+
56+
[#2 Insertion delimiter] = " "
57+
58+
59+
[#3 Content] = 0:24-0:27
60+
0| with aaa as bbb, ccc as ddd:
61+
>---<
62+
63+
[#3 Removal] = 0:20-0:27
64+
0| with aaa as bbb, ccc as ddd:
65+
>-------<
66+
67+
[#3 Leading delimiter] = 0:20-0:24
68+
0| with aaa as bbb, ccc as ddd:
69+
>----<
70+
71+
[#3 Domain] = 0:17-0:27
72+
0| with aaa as bbb, ccc as ddd:
73+
>----------<
74+
75+
[#3 Insertion delimiter] = " "
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
with aaa, bbb as ccc:
2+
pass
3+
---
4+
5+
[#1 Range] = 0:5-0:20
6+
0| with aaa, bbb as ccc:
7+
>---------------<
8+
9+
[#1 Domain] = 0:0-1:8
10+
0| with aaa, bbb as ccc:
11+
>---------------------
12+
1| pass
13+
--------<
14+
15+
16+
[#2 Range] =
17+
[#2 Domain] = 1:4-1:8
18+
1| pass
19+
>----<
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
with aaa:
2+
pass
3+
4+
bbb = ccc
5+
ddd = eee
6+
---
7+
8+
[#1 Range] = 0:5-0:8
9+
0| with aaa:
10+
>---<
11+
12+
[#1 Domain] = 0:0-1:8
13+
0| with aaa:
14+
>---------
15+
1| pass
16+
--------<
17+
18+
19+
[#2 Range] =
20+
[#2 Domain] = 0:0-4:9
21+
0| with aaa:
22+
>---------
23+
1| pass
24+
--------
25+
2|
26+
27+
3| bbb = ccc
28+
---------
29+
4| ddd = eee
30+
---------<
31+
32+
33+
[#3 Range] =
34+
[#3 Domain] = 1:4-1:8
35+
1| pass
36+
>----<
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
with aaa:
2+
pass
3+
---
4+
5+
[Content] = 0:5-0:8
6+
0| with aaa:
7+
>---<
8+
9+
[Removal] = 0:4-0:8
10+
0| with aaa:
11+
>----<
12+
13+
[Leading delimiter] = 0:4-0:5
14+
0| with aaa:
15+
>-<
16+
17+
[Domain] = 0:0-1:8
18+
0| with aaa:
19+
>---------
20+
1| pass
21+
--------<
22+
23+
[Insertion delimiter] = " "

0 commit comments

Comments
 (0)