diff --git a/data/fixtures/scopes/python/interior.loop2.scope b/data/fixtures/scopes/python/interior.loop2.scope new file mode 100644 index 0000000000..606f604f49 --- /dev/null +++ b/data/fixtures/scopes/python/interior.loop2.scope @@ -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] = " " diff --git a/data/fixtures/scopes/python/interior.switchCase.scope b/data/fixtures/scopes/python/interior.switchCase.scope index 04718eacce..45502c3ade 100644 --- a/data/fixtures/scopes/python/interior.switchCase.scope +++ b/data/fixtures/scopes/python/interior.switchCase.scope @@ -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] = " " diff --git a/data/fixtures/scopes/python/interior.with.scope b/data/fixtures/scopes/python/interior.with.scope new file mode 100644 index 0000000000..f5cc28f2d3 --- /dev/null +++ b/data/fixtures/scopes/python/interior.with.scope @@ -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] = " " diff --git a/packages/common/src/scopeSupportFacets/python.ts b/packages/common/src/scopeSupportFacets/python.ts index ce8af97798..48f3410ea9 100644 --- a/packages/common/src/scopeSupportFacets/python.ts +++ b/packages/common/src/scopeSupportFacets/python.ts @@ -48,6 +48,7 @@ export const pythonScopeSupport: LanguageScopeSupportFacetMap = { "interior.switchCase": supported, "interior.ternary": supported, "interior.loop": supported, + "interior.with": supported, element: notApplicable, tags: notApplicable, diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 65d87c1f14..76b56e95bd 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -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", diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 50dac066a4..de802523cc 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -185,6 +185,7 @@ export const scopeSupportFacets = [ "interior.switchCase", "interior.ternary", "interior.loop", + "interior.with", "notebookCell", diff --git a/queries/python.scm b/queries/python.scm index f72144c30c..8251504013 100644 --- a/queries/python.scm +++ b/queries/python.scm @@ -156,6 +156,12 @@ (_) @value ) @_.domain +;;!! with aaa: +;;! ^^^ +(with_statement + body: (_) @interior +) @interior.domain + ;;!! with aaa: ;;! ^^^ ;;! -------- @@ -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 ;;! ^^^^^^^^^^^^ @@ -369,6 +373,7 @@ ;;! ^^^^^ (match_statement subject: (_) @private.switchStatementSubject + body: (_) @interior ) @_.domain ;;!! { "value": 0 } @@ -506,8 +511,8 @@ ;;! ^^^^^^^^^^^^^^^^ (while_statement "while" @branch.start - body: (_) @branch.end -) + body: (_) @branch.end @interior +) @interior.domain (while_statement) @branch.iteration