diff --git a/data/fixtures/scopes/lua/interior.branch.scope b/data/fixtures/scopes/lua/interior.if.scope similarity index 100% rename from data/fixtures/scopes/lua/interior.branch.scope rename to data/fixtures/scopes/lua/interior.if.scope diff --git a/data/fixtures/scopes/python/interior.if.scope b/data/fixtures/scopes/python/interior.if.scope new file mode 100644 index 0000000000..1b902b0cab --- /dev/null +++ b/data/fixtures/scopes/python/interior.if.scope @@ -0,0 +1,48 @@ +if True: + a +elif False: + b +else: + c +--- + +[#1 Content] = +[#1 Removal] = 1:4-1:5 + >-< +1| a + +[#1 Domain] = 0:0-1:5 + >-------- +0| if True: +1| a + -----< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 3:4-3:5 + >-< +3| b + +[#2 Domain] = 2:0-3:5 + >----------- +2| elif False: +3| b + -----< + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 5:4-5:5 + >-< +5| c + +[#3 Domain] = 4:0-5:5 + >----- +4| else: +5| c + -----< + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/python/interior.loop.scope b/data/fixtures/scopes/python/interior.loop.scope new file mode 100644 index 0000000000..66c2c4a322 --- /dev/null +++ b/data/fixtures/scopes/python/interior.loop.scope @@ -0,0 +1,16 @@ +for v in values: + pass +--- + +[Content] = +[Removal] = 1:4-1:8 + >----< +1| pass + +[Domain] = 0:0-1:8 + >---------------- +0| for v in values: +1| pass + --------< + +[Insertion delimiter] = " " 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 new file mode 100644 index 0000000000..45502c3ade --- /dev/null +++ b/data/fixtures/scopes/python/interior.switchCase.scope @@ -0,0 +1,62 @@ +match value: + case 1: + a + case _: + b +--- + +[#1 Content] = 1:4-4:9 + >------- +1| case 1: +2| a +3| case _: +4| b + ---------< + +[#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] = 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 + +[#3 Domain] = 3:4-4:9 + >------- +3| case _: +4| b + ---------< + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/python/interior.ternary.scope b/data/fixtures/scopes/python/interior.ternary.scope new file mode 100644 index 0000000000..fcd8355982 --- /dev/null +++ b/data/fixtures/scopes/python/interior.ternary.scope @@ -0,0 +1,34 @@ +1 if True else 0 +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-0:1 + >-< +0| 1 if True else 0 + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:5-0:9 + >----< +0| 1 if True else 0 + +[#2 Domain] = 0:2-0:9 + >-------< +0| 1 if True else 0 + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 0:15-0:16 + >-< +0| 1 if True else 0 + +[#3 Domain] = 0:10-0:16 + >------< +0| 1 if True else 0 + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/python/interior.try.scope b/data/fixtures/scopes/python/interior.try.scope new file mode 100644 index 0000000000..f84e164e81 --- /dev/null +++ b/data/fixtures/scopes/python/interior.try.scope @@ -0,0 +1,48 @@ +try: + a +except: + b +finally: + c +--- + +[#1 Content] = +[#1 Removal] = 1:4-1:5 + >-< +1| a + +[#1 Domain] = 0:0-1:5 + >---- +0| try: +1| a + -----< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 3:4-3:5 + >-< +3| b + +[#2 Domain] = 2:0-3:5 + >------- +2| except: +3| b + -----< + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = 5:4-5:5 + >-< +5| c + +[#3 Domain] = 4:0-5:5 + >-------- +4| finally: +5| c + -----< + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/python/interior.try2.scope b/data/fixtures/scopes/python/interior.try2.scope new file mode 100644 index 0000000000..3514dad238 --- /dev/null +++ b/data/fixtures/scopes/python/interior.try2.scope @@ -0,0 +1,32 @@ +try: + a +except*: + b +--- + +[#1 Content] = +[#1 Removal] = 1:4-1:5 + >-< +1| a + +[#1 Domain] = 0:0-1:5 + >---- +0| try: +1| a + -----< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 3:4-3:5 + >-< +3| b + +[#2 Domain] = 2:0-3:5 + >-------- +2| except*: +3| b + -----< + +[#2 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/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 601d8c8d6d..2018d4cd54 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -16,5 +16,5 @@ export const luaScopeSupport: LanguageScopeSupportFacetMap = { namedFunction: supported, disqualifyDelimiter: supported, "interior.function": supported, - "interior.branch": supported, + "interior.if": supported, }; diff --git a/packages/common/src/scopeSupportFacets/python.ts b/packages/common/src/scopeSupportFacets/python.ts index b46466c93f..48f3410ea9 100644 --- a/packages/common/src/scopeSupportFacets/python.ts +++ b/packages/common/src/scopeSupportFacets/python.ts @@ -43,6 +43,12 @@ export const pythonScopeSupport: LanguageScopeSupportFacetMap = { "interior.class": supported, "interior.function": supported, "interior.lambda": supported, + "interior.if": supported, + "interior.try": supported, + "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 f39280ee06..76b56e95bd 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -705,6 +705,18 @@ export const scopeSupportFacetInfos: Record< isIteration: true, }, + "interior.element": { + description: "The interior/children of an XML element", + scopeType: { type: "interior" }, + }, + "interior.command": { + description: "The body of a Talon command", + scopeType: { type: "interior" }, + }, + "interior.cell": { + description: "The body of a code cell in markdown", + scopeType: { type: "interior" }, + }, "interior.class": { description: "The body of a class", scopeType: { type: "interior" }, @@ -717,20 +729,28 @@ export const scopeSupportFacetInfos: Record< description: "The body of a lambda/anonymous function", scopeType: { type: "interior" }, }, - "interior.branch": { + "interior.if": { description: "The body of an if/elif/else branch", scopeType: { type: "interior" }, }, - "interior.element": { - description: "The interior/children of an XML element", + "interior.try": { + description: "The body of an try/catch/finally branch", scopeType: { type: "interior" }, }, - "interior.command": { - description: "The body of a Talon command", + "interior.switchCase": { + description: "The body of an switch case branch", scopeType: { type: "interior" }, }, - "interior.cell": { - description: "The body of a code cell in markdown", + "interior.ternary": { + description: "The body of an ternary condition/branch", + scopeType: { type: "interior" }, + }, + "interior.loop": { + 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" }, }, diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index e40b157f32..de802523cc 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -177,10 +177,15 @@ export const scopeSupportFacets = [ "interior.class", "interior.function", "interior.lambda", - "interior.branch", "interior.element", "interior.command", "interior.cell", + "interior.if", + "interior.try", + "interior.switchCase", + "interior.ternary", + "interior.loop", + "interior.with", "notebookCell", diff --git a/queries/python.scm b/queries/python.scm index 26ffbdc567..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 } @@ -394,6 +399,7 @@ (case_clause (case_pattern) @condition.start guard: (_)? @condition.end + consequence: (_) @interior ) @_.domain ;;!! case 0: pass @@ -407,17 +413,17 @@ ;;! ---------------- ( (conditional_expression - "if" + "if" @interior.domain.start . - (_) @condition - ) @_.domain + (_) @condition @interior @interior.domain.end + ) @condition.domain ) ;;!! 1 if True else 0 ;;! ^ ( (conditional_expression - (_) @branch + (_) @branch @interior . "if" ) @@ -427,9 +433,9 @@ ;;! ^ ( (conditional_expression - "else" + "else" @interior.domain.start . - (_) @branch + (_) @branch @interior @interior.domain.end ) ) @@ -456,37 +462,48 @@ ;;!! if True: pass ;;! ^^^^^^^^^^^^^ (if_statement - "if" @branch.start - consequence: (_) @branch.end + "if" @branch.start @interior.domain.start + consequence: (_) @branch.end @interior @interior.domain.end ) ;;!! elif True: pass ;;! ^^^^^^^^^^^^^^^ -(elif_clause) @branch +(elif_clause + consequence: (_) @interior +) @branch @interior.domain ;;!! else: pass ;;! ^^^^^^^^^^ -(else_clause) @branch +(else_clause + body: (_) @interior +) @branch @interior.domain (if_statement) @branch.iteration ;;!! try: pass ;;! ^^^^^^^^^ (try_statement - "try" @branch.start - body: (_) @branch.end + "try" @branch.start @interior.domain.start + body: (_) @branch.end @interior @interior.domain.end ) ;;!! except: pass ;;! ^^^^^^^^^^^^ -[ - (except_clause) - (except_group_clause) -] @branch +(except_clause + (block) @interior +) @branch @interior.domain + +;;!! except*: pass +;;! ^^^^^^^^^^^^^ +(except_group_clause + (block) @interior +) @branch @interior.domain ;;!! finally: pass ;;! ^^^^^^^^^^^^^ -(finally_clause) @branch +(finally_clause + (block) @interior +) @branch @interior.domain (try_statement) @branch.iteration @@ -494,8 +511,8 @@ ;;! ^^^^^^^^^^^^^^^^ (while_statement "while" @branch.start - body: (_) @branch.end -) + body: (_) @branch.end @interior +) @interior.domain (while_statement) @branch.iteration @@ -503,8 +520,8 @@ ;;! ^^^^^^^^^^^^^^^^^^^^ (for_statement "for" @branch.start - body: (_) @branch.end -) + body: (_) @branch.end @interior +) @interior.domain (for_statement) @branch.iteration