Skip to content

Commit 67e4a74

Browse files
Added more python scopes
1 parent e2dac23 commit 67e4a74

File tree

7 files changed

+87
-15
lines changed

7 files changed

+87
-15
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
while True:
2+
pass
3+
---
4+
5+
[Content] =
6+
[Removal] = 1:4-1:8
7+
>----<
8+
1| pass
9+
10+
[Domain] = 0:0-1:8
11+
>-----------
12+
0| while True:
13+
1| pass
14+
--------<
15+
16+
[Insertion delimiter] = " "

data/fixtures/scopes/python/interior.switchCase.scope

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,58 @@ match value:
55
b
66
---
77

8-
[#1 Content] =
9-
[#1 Removal] = 2:8-2:9
10-
>-<
8+
[#1 Content] = 1:4-4:9
9+
>-------
10+
1| case 1:
1111
2| a
12+
3| case _:
13+
4| b
14+
---------<
1215

13-
[#1 Domain] = 1:4-2:9
14-
>-------
16+
[#1 Removal] = 0:12-4:9
17+
>
18+
0| match value:
1519
1| case 1:
1620
2| a
21+
3| case _:
22+
4| b
23+
---------<
24+
25+
[#1 Domain] = 0:0-4:9
26+
>------------
27+
0| match value:
28+
1| case 1:
29+
2| a
30+
3| case _:
31+
4| b
1732
---------<
1833

1934
[#1 Insertion delimiter] = " "
2035

2136

2237
[#2 Content] =
23-
[#2 Removal] = 4:8-4:9
38+
[#2 Removal] = 2:8-2:9
39+
>-<
40+
2| a
41+
42+
[#2 Domain] = 1:4-2:9
43+
>-------
44+
1| case 1:
45+
2| a
46+
---------<
47+
48+
[#2 Insertion delimiter] = " "
49+
50+
51+
[#3 Content] =
52+
[#3 Removal] = 4:8-4:9
2453
>-<
2554
4| b
2655

27-
[#2 Domain] = 3:4-4:9
56+
[#3 Domain] = 3:4-4:9
2857
>-------
2958
3| case _:
3059
4| b
3160
---------<
3261

33-
[#2 Insertion delimiter] = " "
62+
[#3 Insertion delimiter] = " "
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
with file:
2+
pass
3+
---
4+
5+
[Content] =
6+
[Removal] = 1:4-1:8
7+
>----<
8+
1| pass
9+
10+
[Domain] = 0:0-1:8
11+
>----------
12+
0| with file:
13+
1| pass
14+
--------<
15+
16+
[Insertion delimiter] = " "

packages/common/src/scopeSupportFacets/python.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const pythonScopeSupport: LanguageScopeSupportFacetMap = {
4848
"interior.switchCase": supported,
4949
"interior.ternary": supported,
5050
"interior.loop": supported,
51+
"interior.with": supported,
5152

5253
element: notApplicable,
5354
tags: notApplicable,

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@ export const scopeSupportFacetInfos: Record<
749749
description: "The body of an for/while loop",
750750
scopeType: { type: "interior" },
751751
},
752+
"interior.with": {
753+
description: "The body of an with/use/using statement",
754+
scopeType: { type: "interior" },
755+
},
752756

753757
notebookCell: {
754758
description: "A cell in a notebook or a markdown code block",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export const scopeSupportFacets = [
185185
"interior.switchCase",
186186
"interior.ternary",
187187
"interior.loop",
188+
"interior.with",
188189

189190
"notebookCell",
190191

queries/python.scm

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@
156156
(_) @value
157157
) @_.domain
158158

159+
;;!! with aaa:
160+
;;! ^^^
161+
(with_statement
162+
body: (_) @interior
163+
) @interior.domain
164+
159165
;;!! with aaa:
160166
;;! ^^^
161167
;;! --------
@@ -235,11 +241,9 @@
235241
(#allow-multiple! @name)
236242
)
237243

238-
(
239-
(with_statement
240-
(with_clause) @value.iteration @name.iteration
241-
) @value.iteration.domain @name.iteration.domain
242-
)
244+
(with_statement
245+
(with_clause) @value.iteration @name.iteration
246+
) @value.iteration.domain @name.iteration.domain
243247

244248
;;!! lambda str: len(str) > 0
245249
;;! ^^^^^^^^^^^^
@@ -369,6 +373,7 @@
369373
;;! ^^^^^
370374
(match_statement
371375
subject: (_) @private.switchStatementSubject
376+
body: (_) @interior
372377
) @_.domain
373378

374379
;;!! { "value": 0 }
@@ -506,8 +511,8 @@
506511
;;! ^^^^^^^^^^^^^^^^
507512
(while_statement
508513
"while" @branch.start
509-
body: (_) @branch.end
510-
)
514+
body: (_) @branch.end @interior
515+
) @interior.domain
511516

512517
(while_statement) @branch.iteration
513518

0 commit comments

Comments
 (0)