Skip to content

Commit

Permalink
Added more python scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Feb 4, 2025
1 parent e2dac23 commit 67e4a74
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 15 deletions.
16 changes: 16 additions & 0 deletions data/fixtures/scopes/python/interior.loop2.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
while True:
pass
---

[Content] =
[Removal] = 1:4-1:8
>----<
1| pass

[Domain] = 0:0-1:8
>-----------
0| while True:
1| pass
--------<

[Insertion delimiter] = " "
45 changes: 37 additions & 8 deletions data/fixtures/scopes/python/interior.switchCase.scope
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,58 @@ match value:
b
---

[#1 Content] =
[#1 Removal] = 2:8-2:9
>-<
[#1 Content] = 1:4-4:9
>-------
1| case 1:
2| a
3| case _:
4| b
---------<

[#1 Domain] = 1:4-2:9
>-------
[#1 Removal] = 0:12-4:9
>
0| match value:
1| case 1:
2| a
3| case _:
4| b
---------<

[#1 Domain] = 0:0-4:9
>------------
0| match value:
1| case 1:
2| a
3| case _:
4| b
---------<

[#1 Insertion delimiter] = " "


[#2 Content] =
[#2 Removal] = 4:8-4:9
[#2 Removal] = 2:8-2:9
>-<
2| a

[#2 Domain] = 1:4-2:9
>-------
1| case 1:
2| a
---------<

[#2 Insertion delimiter] = " "


[#3 Content] =
[#3 Removal] = 4:8-4:9
>-<
4| b

[#2 Domain] = 3:4-4:9
[#3 Domain] = 3:4-4:9
>-------
3| case _:
4| b
---------<

[#2 Insertion delimiter] = " "
[#3 Insertion delimiter] = " "
16 changes: 16 additions & 0 deletions data/fixtures/scopes/python/interior.with.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with file:
pass
---

[Content] =
[Removal] = 1:4-1:8
>----<
1| pass

[Domain] = 0:0-1:8
>----------
0| with file:
1| pass
--------<

[Insertion delimiter] = " "
1 change: 1 addition & 0 deletions packages/common/src/scopeSupportFacets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const pythonScopeSupport: LanguageScopeSupportFacetMap = {
"interior.switchCase": supported,
"interior.ternary": supported,
"interior.loop": supported,
"interior.with": supported,

element: notApplicable,
tags: notApplicable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,10 @@ export const scopeSupportFacetInfos: Record<
description: "The body of an for/while loop",
scopeType: { type: "interior" },
},
"interior.with": {
description: "The body of an with/use/using statement",
scopeType: { type: "interior" },
},

notebookCell: {
description: "A cell in a notebook or a markdown code block",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const scopeSupportFacets = [
"interior.switchCase",
"interior.ternary",
"interior.loop",
"interior.with",

"notebookCell",

Expand Down
19 changes: 12 additions & 7 deletions queries/python.scm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
(_) @value
) @_.domain

;;!! with aaa:
;;! ^^^
(with_statement
body: (_) @interior
) @interior.domain

;;!! with aaa:
;;! ^^^
;;! --------
Expand Down Expand Up @@ -235,11 +241,9 @@
(#allow-multiple! @name)
)

(
(with_statement
(with_clause) @value.iteration @name.iteration
) @value.iteration.domain @name.iteration.domain
)
(with_statement
(with_clause) @value.iteration @name.iteration
) @value.iteration.domain @name.iteration.domain

;;!! lambda str: len(str) > 0
;;! ^^^^^^^^^^^^
Expand Down Expand Up @@ -369,6 +373,7 @@
;;! ^^^^^
(match_statement
subject: (_) @private.switchStatementSubject
body: (_) @interior
) @_.domain

;;!! { "value": 0 }
Expand Down Expand Up @@ -506,8 +511,8 @@
;;! ^^^^^^^^^^^^^^^^
(while_statement
"while" @branch.start
body: (_) @branch.end
)
body: (_) @branch.end @interior
) @interior.domain

(while_statement) @branch.iteration

Expand Down

0 comments on commit 67e4a74

Please sign in to comment.