From 715e2f9030a7aa40a9fec72b659e1fd26ed7e60e Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 2 Jul 2025 12:31:05 +0200 Subject: [PATCH 1/3] Added more facets to branch if statements --- .../scopes/c/branch.if.elif.else.scope | 45 +++++++ .../branch.if.else.scope} | 24 ++-- data/fixtures/scopes/c/branch.if.scope | 43 +----- .../scopes/csharp/branch.if.elif.else.scope | 45 +++++++ .../scopes/csharp/branch.if.else.scope | 30 +++++ data/fixtures/scopes/csharp/branch.if.scope | 43 +----- .../scopes/java/branch.if.elif.else.scope | 45 +++++++ .../fixtures/scopes/java/branch.if.else.scope | 30 +++++ data/fixtures/scopes/java/branch.if.scope | 43 +----- .../javascript.core/branch.if.elif.else.scope | 45 +++++++ .../javascript.core/branch.if.else.scope | 30 +++++ .../scopes/javascript.core/branch.if.scope | 70 +--------- .../class.iteration.document.scope | 12 +- .../className.iteration.document.scope | 12 +- data/fixtures/scopes/lua/interior.if.scope | 10 +- .../scopes/python/branch.if.else.scope | 38 ++++++ data/fixtures/scopes/python/branch.if.scope | 52 +------- .../scopes/scss/branch.if.elif.else.scope | 45 +++++++ .../fixtures/scopes/scss/branch.if.else.scope | 30 +++++ data/fixtures/scopes/scss/branch.if.scope | 49 +------ data/fixtures/scopes/scss/branch.if3.scope | 10 -- packages/common/src/scopeSupportFacets/c.ts | 2 + .../common/src/scopeSupportFacets/csharp.ts | 2 + packages/common/src/scopeSupportFacets/css.ts | 2 + .../common/src/scopeSupportFacets/html.ts | 2 + .../common/src/scopeSupportFacets/java.ts | 2 + .../src/scopeSupportFacets/javascript.ts | 2 + .../common/src/scopeSupportFacets/json.ts | 2 + packages/common/src/scopeSupportFacets/lua.ts | 3 + .../common/src/scopeSupportFacets/markdown.ts | 2 + .../common/src/scopeSupportFacets/python.ts | 2 + packages/common/src/scopeSupportFacets/scm.ts | 2 + .../scopeSupportFacetInfos.ts | 11 +- .../scopeSupportFacets.types.ts | 2 + .../common/src/scopeSupportFacets/scss.ts | 2 + .../common/src/scopeSupportFacets/talon.ts | 2 + packages/common/src/scopeSupportFacets/xml.ts | 2 + .../common/src/scopeSupportFacets/yaml.ts | 2 + queries/c.scm | 27 ++-- queries/csharp.scm | 23 ++-- queries/java.scm | 28 ++-- queries/javascript.core.scm | 125 +++++++++--------- 42 files changed, 588 insertions(+), 410 deletions(-) create mode 100644 data/fixtures/scopes/c/branch.if.elif.else.scope rename data/fixtures/scopes/{scss/branch.if2.scope => c/branch.if.else.scope} (52%) create mode 100644 data/fixtures/scopes/csharp/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/csharp/branch.if.else.scope create mode 100644 data/fixtures/scopes/java/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/java/branch.if.else.scope create mode 100644 data/fixtures/scopes/javascript.core/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/javascript.core/branch.if.else.scope create mode 100644 data/fixtures/scopes/python/branch.if.else.scope create mode 100644 data/fixtures/scopes/scss/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/scss/branch.if.else.scope delete mode 100644 data/fixtures/scopes/scss/branch.if3.scope diff --git a/data/fixtures/scopes/c/branch.if.elif.else.scope b/data/fixtures/scopes/c/branch.if.elif.else.scope new file mode 100644 index 0000000000..8bf55324af --- /dev/null +++ b/data/fixtures/scopes/c/branch.if.elif.else.scope @@ -0,0 +1,45 @@ +if (true) {} +else if (false) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:5 + >------------ +0| if (true) {} +1| else if (false) {} + -----< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:18 + >------------------< +1| else if (false) {} + +[#2 Removal] = 1:0-2:0 + >------------------ +1| else if (false) {} +2| else {} + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 2:0-2:7 + >-------< +2| else {} + +[#3 Removal] = 1:18-2:7 + > +1| else if (false) {} +2| else {} + -------< + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if2.scope b/data/fixtures/scopes/c/branch.if.else.scope similarity index 52% rename from data/fixtures/scopes/scss/branch.if2.scope rename to data/fixtures/scopes/c/branch.if.else.scope index 0a62177a0b..489c0edd09 100644 --- a/data/fixtures/scopes/scss/branch.if2.scope +++ b/data/fixtures/scopes/c/branch.if.else.scope @@ -1,30 +1,30 @@ -@if true { } -@else { } +if (true) {} +else {} --- [#1 Content] = [#1 Domain] = 0:0-0:12 >------------< -0| @if true { } +0| if (true) {} [#1 Removal] = 0:0-1:0 >------------ -0| @if true { } -1| @else { } +0| if (true) {} +1| else {} < [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Domain] = 1:0-1:9 - >---------< -1| @else { } +[#2 Domain] = 1:0-1:7 + >-------< +1| else {} -[#2 Removal] = 0:12-1:9 +[#2 Removal] = 0:12-1:7 > -0| @if true { } -1| @else { } - ---------< +0| if (true) {} +1| else {} + -------< [#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/c/branch.if.scope b/data/fixtures/scopes/c/branch.if.scope index 8bf55324af..26855fbbaa 100644 --- a/data/fixtures/scopes/c/branch.if.scope +++ b/data/fixtures/scopes/c/branch.if.scope @@ -1,45 +1,10 @@ if (true) {} -else if (false) {} -else {} --- -[#1 Content] = -[#1 Domain] = 0:0-0:12 +[Content] = +[Removal] = +[Domain] = 0:0-0:12 >------------< 0| if (true) {} -[#1 Removal] = 0:0-1:5 - >------------ -0| if (true) {} -1| else if (false) {} - -----< - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 1:0-1:18 - >------------------< -1| else if (false) {} - -[#2 Removal] = 1:0-2:0 - >------------------ -1| else if (false) {} -2| else {} - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 2:0-2:7 - >-------< -2| else {} - -[#3 Removal] = 1:18-2:7 - > -1| else if (false) {} -2| else {} - -------< - -[#3 Insertion delimiter] = "\n" +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/csharp/branch.if.elif.else.scope b/data/fixtures/scopes/csharp/branch.if.elif.else.scope new file mode 100644 index 0000000000..8bf55324af --- /dev/null +++ b/data/fixtures/scopes/csharp/branch.if.elif.else.scope @@ -0,0 +1,45 @@ +if (true) {} +else if (false) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:5 + >------------ +0| if (true) {} +1| else if (false) {} + -----< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:18 + >------------------< +1| else if (false) {} + +[#2 Removal] = 1:0-2:0 + >------------------ +1| else if (false) {} +2| else {} + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 2:0-2:7 + >-------< +2| else {} + +[#3 Removal] = 1:18-2:7 + > +1| else if (false) {} +2| else {} + -------< + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/csharp/branch.if.else.scope b/data/fixtures/scopes/csharp/branch.if.else.scope new file mode 100644 index 0000000000..489c0edd09 --- /dev/null +++ b/data/fixtures/scopes/csharp/branch.if.else.scope @@ -0,0 +1,30 @@ +if (true) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:0 + >------------ +0| if (true) {} +1| else {} + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:7 + >-------< +1| else {} + +[#2 Removal] = 0:12-1:7 + > +0| if (true) {} +1| else {} + -------< + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/csharp/branch.if.scope b/data/fixtures/scopes/csharp/branch.if.scope index a45d366bad..26855fbbaa 100644 --- a/data/fixtures/scopes/csharp/branch.if.scope +++ b/data/fixtures/scopes/csharp/branch.if.scope @@ -1,45 +1,10 @@ if (true) {} -else if (false) {} -else { } --- -[#1 Content] = -[#1 Domain] = 0:0-0:12 +[Content] = +[Removal] = +[Domain] = 0:0-0:12 >------------< 0| if (true) {} -[#1 Removal] = 0:0-1:5 - >------------ -0| if (true) {} -1| else if (false) {} - -----< - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 1:0-1:19 - >-------------------< -1| else if (false) {} - -[#2 Removal] = 1:0-2:0 - >------------------- -1| else if (false) {} -2| else { } - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 2:0-2:8 - >--------< -2| else { } - -[#3 Removal] = 1:19-2:8 - > -1| else if (false) {} -2| else { } - --------< - -[#3 Insertion delimiter] = "\n" +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/java/branch.if.elif.else.scope b/data/fixtures/scopes/java/branch.if.elif.else.scope new file mode 100644 index 0000000000..8bf55324af --- /dev/null +++ b/data/fixtures/scopes/java/branch.if.elif.else.scope @@ -0,0 +1,45 @@ +if (true) {} +else if (false) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:5 + >------------ +0| if (true) {} +1| else if (false) {} + -----< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:18 + >------------------< +1| else if (false) {} + +[#2 Removal] = 1:0-2:0 + >------------------ +1| else if (false) {} +2| else {} + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 2:0-2:7 + >-------< +2| else {} + +[#3 Removal] = 1:18-2:7 + > +1| else if (false) {} +2| else {} + -------< + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/java/branch.if.else.scope b/data/fixtures/scopes/java/branch.if.else.scope new file mode 100644 index 0000000000..489c0edd09 --- /dev/null +++ b/data/fixtures/scopes/java/branch.if.else.scope @@ -0,0 +1,30 @@ +if (true) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:0 + >------------ +0| if (true) {} +1| else {} + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:7 + >-------< +1| else {} + +[#2 Removal] = 0:12-1:7 + > +0| if (true) {} +1| else {} + -------< + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/java/branch.if.scope b/data/fixtures/scopes/java/branch.if.scope index 8bf55324af..26855fbbaa 100644 --- a/data/fixtures/scopes/java/branch.if.scope +++ b/data/fixtures/scopes/java/branch.if.scope @@ -1,45 +1,10 @@ if (true) {} -else if (false) {} -else {} --- -[#1 Content] = -[#1 Domain] = 0:0-0:12 +[Content] = +[Removal] = +[Domain] = 0:0-0:12 >------------< 0| if (true) {} -[#1 Removal] = 0:0-1:5 - >------------ -0| if (true) {} -1| else if (false) {} - -----< - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 1:0-1:18 - >------------------< -1| else if (false) {} - -[#2 Removal] = 1:0-2:0 - >------------------ -1| else if (false) {} -2| else {} - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 2:0-2:7 - >-------< -2| else {} - -[#3 Removal] = 1:18-2:7 - > -1| else if (false) {} -2| else {} - -------< - -[#3 Insertion delimiter] = "\n" +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/branch.if.elif.else.scope b/data/fixtures/scopes/javascript.core/branch.if.elif.else.scope new file mode 100644 index 0000000000..8bf55324af --- /dev/null +++ b/data/fixtures/scopes/javascript.core/branch.if.elif.else.scope @@ -0,0 +1,45 @@ +if (true) {} +else if (false) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:5 + >------------ +0| if (true) {} +1| else if (false) {} + -----< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:18 + >------------------< +1| else if (false) {} + +[#2 Removal] = 1:0-2:0 + >------------------ +1| else if (false) {} +2| else {} + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 2:0-2:7 + >-------< +2| else {} + +[#3 Removal] = 1:18-2:7 + > +1| else if (false) {} +2| else {} + -------< + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/branch.if.else.scope b/data/fixtures/scopes/javascript.core/branch.if.else.scope new file mode 100644 index 0000000000..489c0edd09 --- /dev/null +++ b/data/fixtures/scopes/javascript.core/branch.if.else.scope @@ -0,0 +1,30 @@ +if (true) {} +else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:12 + >------------< +0| if (true) {} + +[#1 Removal] = 0:0-1:0 + >------------ +0| if (true) {} +1| else {} + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:7 + >-------< +1| else {} + +[#2 Removal] = 0:12-1:7 + > +0| if (true) {} +1| else {} + -------< + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/branch.if.scope b/data/fixtures/scopes/javascript.core/branch.if.scope index 2b551be537..26855fbbaa 100644 --- a/data/fixtures/scopes/javascript.core/branch.if.scope +++ b/data/fixtures/scopes/javascript.core/branch.if.scope @@ -1,66 +1,10 @@ -if (true) { - -} -else if (false) { - -} -else { - -} +if (true) {} --- -[#1 Content] = -[#1 Domain] = 0:0-2:1 - >----------- -0| if (true) { -1| -2| } - -< - -[#1 Removal] = 0:0-3:5 - >----------- -0| if (true) { -1| -2| } -3| else if (false) { - -----< - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 3:0-5:1 - >----------------- -3| else if (false) { -4| -5| } - -< - -[#2 Removal] = 3:0-6:0 - >----------------- -3| else if (false) { -4| -5| } -6| else { - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 6:0-8:1 - >------ -6| else { -7| -8| } - -< - -[#3 Removal] = 5:1-8:1 - > -5| } -6| else { -7| -8| } - -< +[Content] = +[Removal] = +[Domain] = 0:0-0:12 + >------------< +0| if (true) {} -[#3 Insertion delimiter] = "\n" +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/class.iteration.document.scope b/data/fixtures/scopes/javascript.core/class.iteration.document.scope index 4d43b4a22a..3e0daecfa3 100644 --- a/data/fixtures/scopes/javascript.core/class.iteration.document.scope +++ b/data/fixtures/scopes/javascript.core/class.iteration.document.scope @@ -1,8 +1,12 @@ -class MyClass { } +int foo; + --- [Range] = -[Domain] = 1:0-1:17 - >-----------------< -1| class MyClass { } +[Domain] = 0:0-2:0 + > +0| +1| int foo; +2| + < diff --git a/data/fixtures/scopes/javascript.core/className.iteration.document.scope b/data/fixtures/scopes/javascript.core/className.iteration.document.scope index 4d43b4a22a..3e0daecfa3 100644 --- a/data/fixtures/scopes/javascript.core/className.iteration.document.scope +++ b/data/fixtures/scopes/javascript.core/className.iteration.document.scope @@ -1,8 +1,12 @@ -class MyClass { } +int foo; + --- [Range] = -[Domain] = 1:0-1:17 - >-----------------< -1| class MyClass { } +[Domain] = 0:0-2:0 + > +0| +1| int foo; +2| + < diff --git a/data/fixtures/scopes/lua/interior.if.scope b/data/fixtures/scopes/lua/interior.if.scope index 2ce1cb35f8..044b13f70b 100644 --- a/data/fixtures/scopes/lua/interior.if.scope +++ b/data/fixtures/scopes/lua/interior.if.scope @@ -1,6 +1,6 @@ -if x < y then +if true then a = 1 -elseif x > y then +elseif false then a = 2 else a = 3 @@ -13,8 +13,8 @@ end 1| a = 1 [#1 Domain] = 0:0-1:9 - >------------- -0| if x < y then + >------------ +0| if true then 1| a = 1 ---------< @@ -28,7 +28,7 @@ end [#2 Domain] = 2:0-3:9 >----------------- -2| elseif x > y then +2| elseif false then 3| a = 2 ---------< diff --git a/data/fixtures/scopes/python/branch.if.else.scope b/data/fixtures/scopes/python/branch.if.else.scope new file mode 100644 index 0000000000..2b540d1500 --- /dev/null +++ b/data/fixtures/scopes/python/branch.if.else.scope @@ -0,0 +1,38 @@ +if True: + pass +else: + pass +--- + +[#1 Content] = +[#1 Domain] = 0:0-1:8 + >-------- +0| if True: +1| pass + --------< + +[#1 Removal] = 0:0-2:0 + >-------- +0| if True: +1| pass +2| else: + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:0-3:8 + >----- +2| else: +3| pass + --------< + +[#2 Removal] = 1:8-3:8 + > +1| pass +2| else: +3| pass + --------< + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/python/branch.if.scope b/data/fixtures/scopes/python/branch.if.scope index 64926e37fe..ce48633dc0 100644 --- a/data/fixtures/scopes/python/branch.if.scope +++ b/data/fixtures/scopes/python/branch.if.scope @@ -1,57 +1,13 @@ if True: pass -elif False: - pass -else: - pass --- -[#1 Content] = -[#1 Domain] = 0:0-1:8 +[Content] = +[Removal] = +[Domain] = 0:0-1:8 >-------- 0| if True: 1| pass --------< -[#1 Removal] = 0:0-2:0 - >-------- -0| if True: -1| pass -2| elif False: - < - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 2:0-3:8 - >----------- -2| elif False: -3| pass - --------< - -[#2 Removal] = 2:0-4:0 - >----------- -2| elif False: -3| pass -4| else: - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 4:0-5:8 - >----- -4| else: -5| pass - --------< - -[#3 Removal] = 3:8-5:8 - > -3| pass -4| else: -5| pass - --------< - -[#3 Insertion delimiter] = "\n" +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if.elif.else.scope b/data/fixtures/scopes/scss/branch.if.elif.else.scope new file mode 100644 index 0000000000..b9d48a2a37 --- /dev/null +++ b/data/fixtures/scopes/scss/branch.if.elif.else.scope @@ -0,0 +1,45 @@ +@if true {} +@else if false {} +@else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| @if true {} + +[#1 Removal] = 0:1-1:6 + >---------- +0| @if true {} +1| @else if false {} + ------< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:17 + >-----------------< +1| @else if false {} + +[#2 Removal] = 1:0-2:0 + >----------------- +1| @else if false {} +2| @else {} + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 2:0-2:8 + >--------< +2| @else {} + +[#3 Removal] = 1:17-2:8 + > +1| @else if false {} +2| @else {} + --------< + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if.else.scope b/data/fixtures/scopes/scss/branch.if.else.scope new file mode 100644 index 0000000000..79a80ae3c6 --- /dev/null +++ b/data/fixtures/scopes/scss/branch.if.else.scope @@ -0,0 +1,30 @@ +@if true {} +@else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| @if true {} + +[#1 Removal] = 0:0-1:0 + >----------- +0| @if true {} +1| @else {} + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:0-1:8 + >--------< +1| @else {} + +[#2 Removal] = 0:11-1:8 + > +0| @if true {} +1| @else {} + --------< + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if.scope b/data/fixtures/scopes/scss/branch.if.scope index 2504e15be7..e54baff8b7 100644 --- a/data/fixtures/scopes/scss/branch.if.scope +++ b/data/fixtures/scopes/scss/branch.if.scope @@ -1,45 +1,10 @@ -@if true { } -@else if false { } -@else { } +@if true {} --- -[#1 Content] = -[#1 Domain] = 0:0-0:12 - >------------< -0| @if true { } +[Content] = +[Removal] = +[Domain] = 0:0-0:11 + >-----------< +0| @if true {} -[#1 Removal] = 0:1-1:6 - >----------- -0| @if true { } -1| @else if false { } - ------< - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 1:0-1:18 - >------------------< -1| @else if false { } - -[#2 Removal] = 1:0-2:0 - >------------------ -1| @else if false { } -2| @else { } - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 2:0-2:9 - >---------< -2| @else { } - -[#3 Removal] = 1:18-2:9 - > -1| @else if false { } -2| @else { } - ---------< - -[#3 Insertion delimiter] = "\n" +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if3.scope b/data/fixtures/scopes/scss/branch.if3.scope deleted file mode 100644 index d2e9d67c17..0000000000 --- a/data/fixtures/scopes/scss/branch.if3.scope +++ /dev/null @@ -1,10 +0,0 @@ -@if true { } ---- - -[Content] = -[Removal] = -[Domain] = 0:0-0:12 - >------------< -0| @if true { } - -[Insertion delimiter] = "\n" diff --git a/packages/common/src/scopeSupportFacets/c.ts b/packages/common/src/scopeSupportFacets/c.ts index 948e64854f..d5d40c66ff 100644 --- a/packages/common/src/scopeSupportFacets/c.ts +++ b/packages/common/src/scopeSupportFacets/c.ts @@ -52,6 +52,8 @@ export const cCoreScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.multiLine": supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, "branch.if.iteration": supported, "branch.switchCase": supported, "branch.switchCase.iteration": supported, diff --git a/packages/common/src/scopeSupportFacets/csharp.ts b/packages/common/src/scopeSupportFacets/csharp.ts index d8bf3063e8..a356c8121d 100644 --- a/packages/common/src/scopeSupportFacets/csharp.ts +++ b/packages/common/src/scopeSupportFacets/csharp.ts @@ -40,6 +40,8 @@ export const csharpScopeSupport: LanguageScopeSupportFacetMap = { "functionName.method.iteration.class": supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, "branch.if.iteration": supported, "branch.try": supported, "branch.try.iteration": supported, diff --git a/packages/common/src/scopeSupportFacets/css.ts b/packages/common/src/scopeSupportFacets/css.ts index bf21d3f18c..1f19ea7e0d 100644 --- a/packages/common/src/scopeSupportFacets/css.ts +++ b/packages/common/src/scopeSupportFacets/css.ts @@ -83,6 +83,8 @@ export const cssScopeSupport: LanguageScopeSupportFacetMap = { attribute: notApplicable, "branch.if.iteration": notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, "branch.switchCase.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/html.ts b/packages/common/src/scopeSupportFacets/html.ts index 1ff7390462..47252f9149 100644 --- a/packages/common/src/scopeSupportFacets/html.ts +++ b/packages/common/src/scopeSupportFacets/html.ts @@ -64,6 +64,8 @@ export const htmlScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.multiLine": notApplicable, "branch.if.iteration": notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, "branch.switchCase.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/java.ts b/packages/common/src/scopeSupportFacets/java.ts index 64c1af6030..e7eba600b3 100644 --- a/packages/common/src/scopeSupportFacets/java.ts +++ b/packages/common/src/scopeSupportFacets/java.ts @@ -51,6 +51,8 @@ export const javaScopeSupport: LanguageScopeSupportFacetMap = { "collectionItem.unenclosed.iteration": supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, "branch.if.iteration": supported, "branch.try": supported, "branch.try.iteration": supported, diff --git a/packages/common/src/scopeSupportFacets/javascript.ts b/packages/common/src/scopeSupportFacets/javascript.ts index 124c2b2d47..aead4b7ea0 100644 --- a/packages/common/src/scopeSupportFacets/javascript.ts +++ b/packages/common/src/scopeSupportFacets/javascript.ts @@ -104,6 +104,8 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "string.multiLine": supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, "branch.if.iteration": supported, "branch.try": supported, "branch.try.iteration": supported, diff --git a/packages/common/src/scopeSupportFacets/json.ts b/packages/common/src/scopeSupportFacets/json.ts index 9c35f04bbe..3d52245d80 100644 --- a/packages/common/src/scopeSupportFacets/json.ts +++ b/packages/common/src/scopeSupportFacets/json.ts @@ -68,6 +68,8 @@ export const jsonScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.multiLine": notApplicable, attribute: notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.if.iteration": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 2018d4cd54..9c5b1e4c8e 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -13,6 +13,9 @@ export const luaScopeSupport: LanguageScopeSupportFacetMap = { functionCallee: supported, map: supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, + "branch.if.iteration": supported, namedFunction: supported, disqualifyDelimiter: supported, "interior.function": supported, diff --git a/packages/common/src/scopeSupportFacets/markdown.ts b/packages/common/src/scopeSupportFacets/markdown.ts index d4c7971395..2eae77e952 100644 --- a/packages/common/src/scopeSupportFacets/markdown.ts +++ b/packages/common/src/scopeSupportFacets/markdown.ts @@ -64,6 +64,8 @@ export const markdownScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.multiLine": notApplicable, attribute: notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.if.iteration": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/python.ts b/packages/common/src/scopeSupportFacets/python.ts index 21e27c385e..e188ed751d 100644 --- a/packages/common/src/scopeSupportFacets/python.ts +++ b/packages/common/src/scopeSupportFacets/python.ts @@ -127,6 +127,8 @@ export const pythonScopeSupport: LanguageScopeSupportFacetMap = { "collectionItem.unenclosed.iteration": supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, "branch.if.iteration": supported, "branch.switchCase": supported, "branch.switchCase.iteration": supported, diff --git a/packages/common/src/scopeSupportFacets/scm.ts b/packages/common/src/scopeSupportFacets/scm.ts index b49728c9c7..1c618d56f9 100644 --- a/packages/common/src/scopeSupportFacets/scm.ts +++ b/packages/common/src/scopeSupportFacets/scm.ts @@ -64,6 +64,8 @@ export const scmScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.multiLine": notApplicable, attribute: notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.if.iteration": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index aab8d5c0a5..c1ed99cc9b 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -492,7 +492,16 @@ export const scopeSupportFacetInfos: Record< }, "branch.if": { - description: "An if/elif/else branch", + description: "An if branch", + scopeType: "branch", + }, + "branch.if.elif.else": { + description: + "An if-elif-else branch. The removal range for the if branch should include the trailing `else` keyword.", + scopeType: "branch", + }, + "branch.if.else": { + description: "An if-else branch", scopeType: "branch", }, "branch.if.iteration": { diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 608c2e2680..15c72ab7fe 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -124,6 +124,8 @@ export const scopeSupportFacets = [ "pairDelimiter", "branch.if", + "branch.if.elif.else", + "branch.if.else", "branch.if.iteration", "branch.try", "branch.try.iteration", diff --git a/packages/common/src/scopeSupportFacets/scss.ts b/packages/common/src/scopeSupportFacets/scss.ts index 41b333de1c..b99f262ee6 100644 --- a/packages/common/src/scopeSupportFacets/scss.ts +++ b/packages/common/src/scopeSupportFacets/scss.ts @@ -29,6 +29,8 @@ export const scssScopeSupport: LanguageScopeSupportFacetMap = { ifStatement: supported, "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, "branch.if.iteration": supported, "condition.if": supported, diff --git a/packages/common/src/scopeSupportFacets/talon.ts b/packages/common/src/scopeSupportFacets/talon.ts index c20adeea91..bb413db6df 100644 --- a/packages/common/src/scopeSupportFacets/talon.ts +++ b/packages/common/src/scopeSupportFacets/talon.ts @@ -84,6 +84,8 @@ export const talonScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.multiLine": notApplicable, attribute: notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.if.iteration": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/xml.ts b/packages/common/src/scopeSupportFacets/xml.ts index fb725263e2..4fdb4637bb 100644 --- a/packages/common/src/scopeSupportFacets/xml.ts +++ b/packages/common/src/scopeSupportFacets/xml.ts @@ -64,6 +64,8 @@ export const xmlScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.singleLine": notApplicable, "argumentList.formal.constructor.multiLine": notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.if.iteration": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, diff --git a/packages/common/src/scopeSupportFacets/yaml.ts b/packages/common/src/scopeSupportFacets/yaml.ts index 168946be81..00b2a1444f 100644 --- a/packages/common/src/scopeSupportFacets/yaml.ts +++ b/packages/common/src/scopeSupportFacets/yaml.ts @@ -74,6 +74,8 @@ export const yamlScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.constructor.multiLine": notApplicable, attribute: notApplicable, "branch.if": notApplicable, + "branch.if.elif.else": notApplicable, + "branch.if.else": notApplicable, "branch.if.iteration": notApplicable, "branch.loop": notApplicable, "branch.loop.iteration": notApplicable, diff --git a/queries/c.scm b/queries/c.scm index d98a24cef1..74a4c91727 100644 --- a/queries/c.scm +++ b/queries/c.scm @@ -20,17 +20,16 @@ (expression_statement) (for_statement) (goto_statement) - (if_statement) (labeled_statement) (return_statement) (switch_statement) (while_statement) ;; Disabled on purpose. This is the entire body of statements. ;; (compound_statement) + ;; Disabled on purpose. We have a better definition of this below. + ;; (if_statement) ] @statement -(if_statement) @ifStatement - ( (translation_unit) @statement.iteration @class.iteration @className.iteration (#document-range! @statement.iteration @class.iteration @className.iteration) @@ -241,7 +240,7 @@ . (_)? @_.trailing.startOf ) @_dummy - (#not-type? @argumentOrParameter "comment") + (#not-type? @argumentOrParameter comment) (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) @@ -255,7 +254,7 @@ . (_)? @_.trailing.startOf ) @_dummy - (#not-type? @argumentOrParameter "comment") + (#not-type? @argumentOrParameter comment) (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) @@ -288,6 +287,13 @@ (#empty-single-multi-delimiter! @argumentList @argumentList "" ", " ",\n") ) @argumentList.domain @argumentOrParameter.iteration.domain +;;!! if () {} else {} +;;! ^^^^^^^^^^^^^^^^ +( + (if_statement) @ifStatement @statement @branch.iteration + (#not-parent-type? @ifStatement else_clause) +) + ;;!! if () {} ;;! ^^^^^^^^ ( @@ -299,10 +305,10 @@ "}" @interior.end.startOf ) @branch.end @branch.removal.end @interior.domain.end alternative: (else_clause - (if_statement) @branch.removal.end.startOf - )? + (if_statement)? @branch.removal.end.startOf + )? @branch.removal.end.startOf ) @condition.domain - (#not-parent-type? @condition.domain "else_clause") + (#not-parent-type? @condition.domain else_clause) (#child-range! @condition 0 -1 true true) ) @@ -331,11 +337,6 @@ ) @branch @interior.domain ) -( - (if_statement) @branch.iteration - (#not-parent-type? @branch.iteration "else_clause") -) - ;;!! for (int i = 0; i < size; ++i) {} ;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;;! ^^^^^^^^ diff --git a/queries/csharp.scm b/queries/csharp.scm index 2b0833e330..06a94e11d1 100644 --- a/queries/csharp.scm +++ b/queries/csharp.scm @@ -33,7 +33,6 @@ (for_each_statement) (for_statement) (goto_statement) - (if_statement) (labeled_statement) (local_declaration_statement) (local_function_statement) @@ -46,6 +45,8 @@ (using_statement) (while_statement) (yield_statement) + ;; Disabled on purpose. We have a better definition of this below. + ;; (if_statement) ] @statement ( @@ -85,9 +86,12 @@ (#not-type? @_.domain try_statement if_statement) ) -;;!! if () {} -;;! ^^^^^^^^ -(if_statement) @ifStatement +;;!! if () {} else {} +;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +( + (if_statement) @ifStatement @statement @branch.iteration + (#not-parent-type? @ifStatement if_statement) +) ;;!! if () {} ;;! ^^^^^^^^ @@ -95,10 +99,12 @@ (if_statement condition: (_) @condition consequence: (_) @branch.end.endOf @branch.removal.end.endOf - alternative: (_)? @branch.removal.end.startOf + "else"? @branch.removal.end.startOf + alternative: (if_statement)? @branch.removal.end.startOf ) @branch.start.startOf @branch.removal.start.startOf @condition.domain (#not-parent-type? @condition.domain if_statement) ) + ( (if_statement consequence: (_ @@ -132,13 +138,6 @@ ) @branch.end @interior.domain.end.endOf ) -;;!! if () {} else if () {} else {} -;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -( - (if_statement) @branch.iteration - (#not-parent-type? @branch.iteration if_statement) -) - ;;!! try () {} ;;! ^^^^^^^^^ (try_statement diff --git a/queries/java.scm b/queries/java.scm index e6d86e9a09..733a1b0cf8 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -18,7 +18,6 @@ (enhanced_for_statement) (expression_statement) (for_statement) - (if_statement) (labeled_statement) (local_variable_declaration) (return_statement) @@ -29,13 +28,16 @@ (try_with_resources_statement) (while_statement) (yield_statement) + (method_declaration) + (constructor_declaration) + (field_declaration) ;; exceptions ;; ";", ;; "block", - (method_declaration) - (constructor_declaration) - (field_declaration) + + ;; Disabled on purpose. We have a better definition of this below. + ;; (if_statement) ] @statement [ @@ -194,7 +196,7 @@ (_) @interior.start (_)? @interior.end . - (#not-type? @interior.start "block") + (#not-type? @interior.start block) ) @_.domain (switch_expression @@ -204,11 +206,11 @@ ) ) @condition.iteration.domain @branch.iteration.domain -;;!! if (value) {} -;;! ^^^^^^^^^^^^^ +;;!! if () {} else {} +;;! ^^^^^^^^^^^^^^^^ ( - (if_statement) @ifStatement - (#not-parent-type? @ifStatement "if_statement") + (if_statement) @ifStatement @statement @branch.iteration + (#not-parent-type? @ifStatement if_statement) ) ;;!! if () {} @@ -221,9 +223,10 @@ "{" @interior.start.endOf "}" @interior.end.startOf ) @branch.end @branch.removal.end @interior.domain.end.endOf + "else"? @branch.removal.end.startOf alternative: (if_statement)? @branch.removal.end.startOf ) @condition.domain - (#not-parent-type? @condition.domain "if_statement") + (#not-parent-type? @condition.domain if_statement) (#child-range! @condition 0 -1 true true) ) @@ -251,11 +254,6 @@ ) @branch.end @interior.domain.end.endOf ) -( - (if_statement) @branch.iteration - (#not-parent-type? @branch.iteration "if_statement") -) - ;;!! try {} ;;! ^^^^^^ (try_statement diff --git a/queries/javascript.core.scm b/queries/javascript.core.scm index 6d343f465b..c0a33f73ce 100644 --- a/queries/javascript.core.scm +++ b/queries/javascript.core.scm @@ -3,6 +3,56 @@ ;; https://github.com/tree-sitter/tree-sitter-javascript/blob/master/src/grammar.json +;; Statements that are not a child of an export statement +;; Generated by the following command: +;; > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-typescript/4c20b54771e4b390ee058af2930feb2cd55f2bf8/typescript/src/node-types.json \ +;; | jq '[.[] | select(.type == "statement" or .type == "declaration") | .subtypes[].type]' +( + [ + (break_statement) + (class_declaration) + (continue_statement) + (debugger_statement) + (declaration) + (do_statement) + (empty_statement) + (export_statement) + (expression_statement) + (for_in_statement) + (for_statement) + (generator_function_declaration) + (import_statement) + (labeled_statement) + (lexical_declaration) + (return_statement) + (switch_statement) + (throw_statement) + (try_statement) + (variable_declaration) + (while_statement) + (with_statement) + + ;; Disabled on purpose. We have a better definition of this below. + ;; (if_statement) + ;; This is disabled since we want the whole statement and not just the block + ;; (statement_block) + + ;; Manually added + (method_definition) + ] @statement + (#not-parent-type? @statement export_statement) +) + +( + (program) @statement.iteration @class.iteration @className.iteration + (#document-range! @statement.iteration @class.iteration @className.iteration) +) + +( + (program) @name.iteration @value.iteration @type.iteration + (#document-range! @name.iteration @value.iteration @type.iteration) +) + ;; `name` scope without `export` ( (_ @@ -422,11 +472,6 @@ right: (_) @value ) @_.domain -( - (program) @name.iteration @value.iteration @type.iteration - (#document-range! @name.iteration @value.iteration @type.iteration) -) - ;;!! { } ;;! ^ ( @@ -576,8 +621,6 @@ ] ) @class @type @_.domain -(program) @class.iteration @className.iteration - ;;!! true ? 0 : 1 ;;! ^^^^ ;;! ^ ^ @@ -643,19 +686,22 @@ body: (_) @interior.start body: (_)? @interior.end . - (#not-type? @interior.start "statement_block") + (#not-type? @interior.start statement_block) ) @_.domain (switch_default body: (_) @interior.start body: (_)? @interior.end . - (#not-type? @interior.start "statement_block") + (#not-type? @interior.start statement_block) ) @_.domain -;;!! if () {} -;;! ^^^^^^^^ -(if_statement) @ifStatement +;;!! if () {} else {} +;;! ^^^^^^^^^^^^^^^^ +( + (if_statement) @ifStatement @statement @branch.iteration + (#not-parent-type? @ifStatement else_clause) +) ;;!! if () {} ;;! ^^^^^^^^ @@ -667,9 +713,9 @@ "{" @interior.start.endOf "}" @interior.end.startOf ) @branch.end.endOf @branch.removal.end.endOf @interior.domain.end.endOf - alternative: (_ - (if_statement) @branch.removal.end.startOf - )? + alternative: (else_clause + (if_statement)? @branch.removal.end.startOf + )? @branch.removal.end.startOf ) @condition.domain (#not-parent-type? @condition.domain else_clause) (#child-range! @condition 0 -1 true true) @@ -698,13 +744,6 @@ ) ) @branch @interior.domain -;;!! if () {} else if () {} else {} -;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -( - (if_statement) @branch.iteration - (#not-parent-type? @branch.iteration else_clause) -) - ;;!! try () {} ;;! ^^^^^^^^^ (try_statement @@ -750,48 +789,6 @@ value: (_) @value @collectionKey.trailing.startOf ) @_.domain -;; Statements that are not a child of an export statement -;; Generated by the following command: -;; > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-typescript/4c20b54771e4b390ee058af2930feb2cd55f2bf8/typescript/src/node-types.json \ -;; | jq '[.[] | select(.type == "statement" or .type == "declaration") | .subtypes[].type]' -( - [ - (break_statement) - (class_declaration) - (continue_statement) - (debugger_statement) - (declaration) - (do_statement) - (empty_statement) - (export_statement) - (expression_statement) - (for_in_statement) - (for_statement) - (generator_function_declaration) - (if_statement) - (import_statement) - (labeled_statement) - (lexical_declaration) - (return_statement) - ;; (statement_block), This is disabled since we want the whole statement and not just the block - (switch_statement) - (throw_statement) - (try_statement) - (variable_declaration) - (while_statement) - (with_statement) - - ;; Manually added1 - (method_definition) - ] @statement - (#not-parent-type? @statement export_statement) -) - -( - (program) @statement.iteration - (#document-range! @statement.iteration) -) - ;;!! function foo(aaa, bbb) {} ;;! ^^^ ^^^ ( From 0e1dbeb54e4c128f332e22eb235324a7b9cbbaff Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 2 Jul 2025 13:17:37 +0200 Subject: [PATCH 2/3] python --- .../scopes/python/branch.if.elif.else.scope | 57 +++++++++++++++++++ queries/python.scm | 36 +++++++++--- 2 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 data/fixtures/scopes/python/branch.if.elif.else.scope diff --git a/data/fixtures/scopes/python/branch.if.elif.else.scope b/data/fixtures/scopes/python/branch.if.elif.else.scope new file mode 100644 index 0000000000..90331c9fad --- /dev/null +++ b/data/fixtures/scopes/python/branch.if.elif.else.scope @@ -0,0 +1,57 @@ +if True: + pass +elif False: + pass +else: + pass +--- + +[#1 Content] = +[#1 Domain] = 0:0-1:8 + >-------- +0| if True: +1| pass + --------< + +[#1 Removal] = 0:0-2:2 + >-------- +0| if True: +1| pass +2| elif False: + --< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:0-3:8 + >----------- +2| elif False: +3| pass + --------< + +[#2 Removal] = 2:0-4:0 + >----------- +2| elif False: +3| pass +4| else: + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 4:0-5:8 + >----- +4| else: +5| pass + --------< + +[#3 Removal] = 3:8-5:8 + > +3| pass +4| else: +5| pass + --------< + +[#3 Insertion delimiter] = "\n" diff --git a/queries/python.scm b/queries/python.scm index 3ffaba8969..3873da8c35 100644 --- a/queries/python.scm +++ b/queries/python.scm @@ -18,7 +18,6 @@ (function_definition) (future_import_statement) (global_statement) - (if_statement) (import_from_statement) (import_statement) (match_statement) @@ -30,6 +29,8 @@ (try_statement) (while_statement) (with_statement) + ;; Disabled on purpose. We have a better definition of this below. + ;; (if_statement) ] @statement ;;!! a = 25 @@ -395,10 +396,6 @@ ")" @value.iteration.end.startOf @name.iteration.end.startOf @type.iteration.end.startOf ) -;;!! if true: pass -;;! ^^^^^^^^^^^^^ -(if_statement) @ifStatement - ;;!! foo() ;;! ^^^^^ (call) @functionCall @@ -507,11 +504,34 @@ (#not-parent-type? @_.removal case_clause) ) @_.domain +;;!! if true: pass else: pass +;;! ^^^^^^^^^^^^^^^^^^^^^^^^ +(if_statement) @ifStatement @statement @branch.iteration + +;;!! if True: pass +;;! ^^^^^^^^^^^^^ +(if_statement + "if" @interior.domain.start + consequence: (_) @interior @interior.domain.end +) + ;;!! if True: pass ;;! ^^^^^^^^^^^^^ (if_statement - "if" @branch.start @interior.domain.start - consequence: (_) @branch.end @interior @interior.domain.end + "if" @branch.start @branch.removal.start + consequence: (_) @branch.end @branch.removal.end + alternative: (else_clause)? @branch.removal.end.startOf +) + +;;!! if True: pass elif False: pass +;;! ^^^^^^^^^^^^^ +(if_statement + "if" @branch.start @branch.removal.start + consequence: (_) @branch.end @branch.removal.end + alternative: (elif_clause + "elif" @branch.removal.end.startOf + (#character-range! @branch.removal.end.startOf 2) + ) ) ;;!! elif True: pass @@ -526,8 +546,6 @@ body: (_) @interior ) @branch @interior.domain -(if_statement) @branch.iteration - ;;!! try: pass ;;! ^^^^^^^^^ (try_statement From 9b32040508693b6c86043d5c92befebd95ab7d9a Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 2 Jul 2025 13:54:41 +0200 Subject: [PATCH 3/3] lua --- .../scopes/lua/branch.if.elif.else.scope | 58 ++++++++++++ data/fixtures/scopes/lua/branch.if.else.scope | 39 ++++++++ .../scopes/lua/branch.if.iteration.scope | 20 +++++ data/fixtures/scopes/lua/branch.if.scope | 72 ++++----------- data/fixtures/scopes/lua/condition.if.scope | 62 +++++++++++++ data/fixtures/scopes/lua/ifStatement.scope | 23 +++++ packages/common/src/scopeSupportFacets/lua.ts | 18 ++-- queries/lua.scm | 88 +++++++++---------- queries/scss.scm | 2 +- 9 files changed, 276 insertions(+), 106 deletions(-) create mode 100644 data/fixtures/scopes/lua/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/lua/branch.if.else.scope create mode 100644 data/fixtures/scopes/lua/branch.if.iteration.scope create mode 100644 data/fixtures/scopes/lua/condition.if.scope create mode 100644 data/fixtures/scopes/lua/ifStatement.scope diff --git a/data/fixtures/scopes/lua/branch.if.elif.else.scope b/data/fixtures/scopes/lua/branch.if.elif.else.scope new file mode 100644 index 0000000000..9e15bd8243 --- /dev/null +++ b/data/fixtures/scopes/lua/branch.if.elif.else.scope @@ -0,0 +1,58 @@ +if true then + a = 1 +elseif false then + a = 2 +else + a = 3 +end +--- + +[#1 Content] = +[#1 Domain] = 0:0-1:9 + >------------ +0| if true then +1| a = 1 + ---------< + +[#1 Removal] = 0:0-2:4 + >------------ +0| if true then +1| a = 1 +2| elseif false then + ----< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:0-3:9 + >----------------- +2| elseif false then +3| a = 2 + ---------< + +[#2 Removal] = 2:0-4:0 + >----------------- +2| elseif false then +3| a = 2 +4| else + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 4:0-5:9 + >---- +4| else +5| a = 3 + ---------< + +[#3 Removal] = 4:0-6:0 + >---- +4| else +5| a = 3 +6| end + < + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/lua/branch.if.else.scope b/data/fixtures/scopes/lua/branch.if.else.scope new file mode 100644 index 0000000000..eff1aad40d --- /dev/null +++ b/data/fixtures/scopes/lua/branch.if.else.scope @@ -0,0 +1,39 @@ +if true then + a = 1 +else + a = 2 +end +--- + +[#1 Content] = +[#1 Domain] = 0:0-1:9 + >------------ +0| if true then +1| a = 1 + ---------< + +[#1 Removal] = 0:0-2:0 + >------------ +0| if true then +1| a = 1 +2| else + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:0-3:9 + >---- +2| else +3| a = 2 + ---------< + +[#2 Removal] = 2:0-4:0 + >---- +2| else +3| a = 2 +4| end + < + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/lua/branch.if.iteration.scope b/data/fixtures/scopes/lua/branch.if.iteration.scope new file mode 100644 index 0000000000..d3e9385ac9 --- /dev/null +++ b/data/fixtures/scopes/lua/branch.if.iteration.scope @@ -0,0 +1,20 @@ +if true then + a = 1 +elseif false then + a = 2 +else + a = 3 +end +--- + +[Range] = +[Domain] = 0:0-6:3 + >------------ +0| if true then +1| a = 1 +2| elseif false then +3| a = 2 +4| else +5| a = 3 +6| end + ---< diff --git a/data/fixtures/scopes/lua/branch.if.scope b/data/fixtures/scopes/lua/branch.if.scope index 3f35d2c647..66c1811aaf 100644 --- a/data/fixtures/scopes/lua/branch.if.scope +++ b/data/fixtures/scopes/lua/branch.if.scope @@ -1,58 +1,20 @@ -if x < y then - print("x is less than y") -elseif x > y then - print("x is greater than y") -else - print("x is equal to y") +if true then + a = 1 end --- -[#1 Content] = -[#1 Domain] = 0:0-1:29 - >------------- -0| if x < y then -1| print("x is less than y") - -----------------------------< - -[#1 Removal] = 0:0-2:0 - >------------- -0| if x < y then -1| print("x is less than y") -2| elseif x > y then - < - -[#1 Insertion delimiter] = "\n" - - -[#2 Content] = -[#2 Domain] = 2:0-3:32 - >----------------- -2| elseif x > y then -3| print("x is greater than y") - --------------------------------< - -[#2 Removal] = 2:0-4:0 - >----------------- -2| elseif x > y then -3| print("x is greater than y") -4| else - < - -[#2 Insertion delimiter] = "\n" - - -[#3 Content] = -[#3 Domain] = 4:0-5:28 - >---- -4| else -5| print("x is equal to y") - ----------------------------< - -[#3 Removal] = 4:0-6:0 - >---- -4| else -5| print("x is equal to y") -6| end - < - -[#3 Insertion delimiter] = "\n" +[Content] = +[Domain] = 0:0-1:9 + >------------ +0| if true then +1| a = 1 + ---------< + +[Removal] = 0:0-2:3 + >------------ +0| if true then +1| a = 1 +2| end + ---< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/lua/condition.if.scope b/data/fixtures/scopes/lua/condition.if.scope new file mode 100644 index 0000000000..19d71b3b2e --- /dev/null +++ b/data/fixtures/scopes/lua/condition.if.scope @@ -0,0 +1,62 @@ +if true then + a = 1 +elseif false then + a = 1 +else + a = 1 +end +--- + +[#1 Content] = 0:3-0:7 + >----< +0| if true then + +[#1 Removal] = 0:3-0:8 + >-----< +0| if true then + +[#1 Leading delimiter] = 0:2-0:3 + >-< +0| if true then + +[#1 Trailing delimiter] = 0:7-0:8 + >-< +0| if true then + +[#1 Domain] = 0:0-6:3 + >------------ +0| if true then +1| a = 1 +2| elseif false then +3| a = 1 +4| else +5| a = 1 +6| end + ---< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 2:7-2:12 + >-----< +2| elseif false then + +[#2 Removal] = 2:7-2:13 + >------< +2| elseif false then + +[#2 Leading delimiter] = 2:6-2:7 + >-< +2| elseif false then + +[#2 Trailing delimiter] = 2:12-2:13 + >-< +2| elseif false then + +[#2 Domain] = 2:0-3:9 + >----------------- +2| elseif false then +3| a = 1 + ---------< + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/lua/ifStatement.scope b/data/fixtures/scopes/lua/ifStatement.scope new file mode 100644 index 0000000000..0ae5d2a88f --- /dev/null +++ b/data/fixtures/scopes/lua/ifStatement.scope @@ -0,0 +1,23 @@ +if true then + a = 1 +elseif false then + a = 1 +else + a = 1 +end +--- + +[Content] = +[Removal] = +[Domain] = 0:0-6:3 + >------------ +0| if true then +1| a = 1 +2| elseif false then +3| a = 1 +4| else +5| a = 1 +6| end + ---< + +[Insertion delimiter] = "\n" diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 9c5b1e4c8e..0e10f302dc 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -4,20 +4,28 @@ import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; const { supported, notApplicable } = ScopeSupportFacetLevel; export const luaScopeSupport: LanguageScopeSupportFacetMap = { - "key.attribute": notApplicable, tags: notApplicable, + functionCallee: supported, + map: supported, + ifStatement: supported, + namedFunction: supported, + disqualifyDelimiter: supported, + + "key.attribute": notApplicable, + "name.assignment": supported, "name.variable": supported, + "value.assignment": supported, "value.variable": supported, - functionCallee: supported, - map: supported, + "branch.if": supported, "branch.if.elif.else": supported, "branch.if.else": supported, "branch.if.iteration": supported, - namedFunction: supported, - disqualifyDelimiter: supported, + + "condition.if": supported, + "interior.function": supported, "interior.if": supported, }; diff --git a/queries/lua.scm b/queries/lua.scm index 0a5a728a7e..973aaf2f3e 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -44,62 +44,60 @@ ) ;; Conditionals -;;!! if x < y then -;;! ---^^^^^----- -;;! ---xxxxxx---- -;;!! end -;;! --- + +;;!! if true then end +;;! ^^^^^^^^^^^^^^^^ +;;! ^^^^ (if_statement - _ @condition.domain.start.startOf + "if" @interior.domain.start condition: (_) @condition - consequence: (_) - !alternative - "end" @condition.domain.end.endOf + consequence: (_) @interior @interior.domain.end +) @ifStatement @condition.domain @branch.iteration + +;;!! if true then end +;;! ^^^^^^^^^^^^ +(if_statement + "if" @branch.start @branch.removal.start + consequence: (_) @branch.end + . + "end" @branch.removal.end ) -;;!! if x < y then -;;! ---^^^^^----- -;;! ---xxxxxx---- -;;!! elseif x < y then +;;!! if true then elseif false then +;;! ^^^^^^^^^^^^ (if_statement - _ @_.domain.start.startOf - condition: (_) @condition - consequence: (_) @_.domain.end.endOf - alternative: (_) + "if" @branch.start @branch.removal.start.startOf + consequence: (_) @branch.end + . + alternative: (elseif_statement) @branch.removal.end.startOf + (#character-range! @branch.removal.end.startOf 4) +) + +;;!! if true then else then +;;! ^^^^^^^^^^^^ +(if_statement + "if" @branch.start @branch.removal.start.startOf + consequence: (_) @branch.end + . + alternative: (else_statement) @branch.removal.end.startOf ) -;;!! elseif x < y then -;;! -------^^^^^----- -;;! -------xxxxxx---- +;;!! elseif true then +;;! ^^^^^^^^^^^^^^^^ +;;! ^^^^ (elseif_statement condition: (_) @condition -) @_.domain + consequence: (_) @interior +) @branch @_.domain -;;!! -(if_statement - "if" @branch.start @interior.domain.start - consequence: (_) @branch.end @interior @interior.domain.end -) @ifStatement @branch.iteration @condition.iteration - -;;!! if x < y then -;;!! print("x smaller") -;;!! else -;;! ^^^^ -;;!! print("x bigger") -;;! ^^^^^^^^^^^^^^^^^ -;;!! end -[ - (elseif_statement - consequence: (_) @interior - ) - (else_statement - body: (_) @interior - ) -] @branch @interior.domain +;;!! else then +;;! ^^^^^^^^^ +(else_statement + body: (_) @interior +) @branch @interior.domain -;;!! while i <= 5 do -;;! ^^^^^^ -;;! xxxxxx +;;!! while true do +;;! ^^^^ (while_statement condition: (_) @condition ) @_.domain diff --git a/queries/scss.scm b/queries/scss.scm index db3c4ddd50..ac2c844681 100644 --- a/queries/scss.scm +++ b/queries/scss.scm @@ -46,7 +46,7 @@ (if_clause (condition) @condition ) -) @ifStatement @branch.iteration @condition.domain +) @ifStatement @condition.domain @branch.iteration ;;!! @if true { } @else if false { } ;;! xxxxxxxxxxxxxxxxxxx