From 6c055cfa6860257b902a355ef8e5042b1f439fcf Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 28 Jun 2025 21:40:08 +0200 Subject: [PATCH] Update scss branch removal range for if statements --- data/fixtures/scopes/scss/branch.if.scope | 70 ++++----- data/fixtures/scopes/scss/branch.if2.scope | 30 ++++ data/fixtures/scopes/scss/branch.if3.scope | 10 ++ data/fixtures/scopes/scss/condition.if.scope | 74 +++++----- data/fixtures/scopes/scss/ifStatement.scope | 33 ++--- data/fixtures/scopes/scss/interior.if.scope | 144 ++++++------------- queries/scss.scm | 25 ++-- 7 files changed, 174 insertions(+), 212 deletions(-) create mode 100644 data/fixtures/scopes/scss/branch.if2.scope create mode 100644 data/fixtures/scopes/scss/branch.if3.scope diff --git a/data/fixtures/scopes/scss/branch.if.scope b/data/fixtures/scopes/scss/branch.if.scope index 4f871466e7..2504e15be7 100644 --- a/data/fixtures/scopes/scss/branch.if.scope +++ b/data/fixtures/scopes/scss/branch.if.scope @@ -1,59 +1,45 @@ -* { - @if true { } - @else if false { } - @else { } -} +@if true { } +@else if false { } +@else { } --- [#1 Content] = -[#1 Domain] = 1:2-1:14 - >------------< -1| @if true { } +[#1 Domain] = 0:0-0:12 + >------------< +0| @if true { } -[#1 Removal] = 1:3-2:8 - >----------- -1| @if true { } -2| @else if false { } - --------< - -[#1 Leading delimiter] = 1:0-1:2 - >--< -1| @if true { } +[#1 Removal] = 0:1-1:6 + >----------- +0| @if true { } +1| @else if false { } + ------< [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Domain] = 2:2-2:20 - >------------------< -2| @else if false { } - -[#2 Removal] = 2:0-3:0 - >-------------------- -2| @else if false { } -3| @else { } +[#2 Domain] = 1:0-1:18 + >------------------< +1| @else if false { } + +[#2 Removal] = 1:0-2:0 + >------------------ +1| @else if false { } +2| @else { } < -[#2 Leading delimiter] = 2:0-2:2 - >--< -2| @else if false { } - [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Domain] = 3:2-3:11 - >---------< -3| @else { } - -[#3 Removal] = 3:0-4:0 - >----------- -3| @else { } -4| } - < - -[#3 Leading delimiter] = 3:0-3:2 - >--< -3| @else { } +[#3 Domain] = 2:0-2:9 + >---------< +2| @else { } + +[#3 Removal] = 1:18-2:9 + > +1| @else if false { } +2| @else { } + ---------< [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if2.scope b/data/fixtures/scopes/scss/branch.if2.scope new file mode 100644 index 0000000000..0a62177a0b --- /dev/null +++ b/data/fixtures/scopes/scss/branch.if2.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:9 + >---------< +1| @else { } + +[#2 Removal] = 0:12-1:9 + > +0| @if true { } +1| @else { } + ---------< + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/branch.if3.scope b/data/fixtures/scopes/scss/branch.if3.scope new file mode 100644 index 0000000000..d2e9d67c17 --- /dev/null +++ b/data/fixtures/scopes/scss/branch.if3.scope @@ -0,0 +1,10 @@ +@if true { } +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:12 + >------------< +0| @if true { } + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/condition.if.scope b/data/fixtures/scopes/scss/condition.if.scope index 0260d9e89a..2d5f851b07 100644 --- a/data/fixtures/scopes/scss/condition.if.scope +++ b/data/fixtures/scopes/scss/condition.if.scope @@ -1,54 +1,52 @@ -* { - @if true { } - @else if false { } - @else { } -} +@if true { } +@else if false { } +@else { } --- -[#1 Content] = 1:6-1:10 - >----< -1| @if true { } +[#1 Content] = 0:4-0:8 + >----< +0| @if true { } -[#1 Removal] = 1:6-1:11 - >-----< -1| @if true { } +[#1 Removal] = 0:4-0:9 + >-----< +0| @if true { } -[#1 Leading delimiter] = 1:5-1:6 - >-< -1| @if true { } +[#1 Leading delimiter] = 0:3-0:4 + >-< +0| @if true { } -[#1 Trailing delimiter] = 1:10-1:11 - >-< -1| @if true { } +[#1 Trailing delimiter] = 0:8-0:9 + >-< +0| @if true { } -[#1 Domain] = 1:2-3:11 - >------------ -1| @if true { } -2| @else if false { } -3| @else { } - -----------< +[#1 Domain] = 0:0-2:9 + >------------ +0| @if true { } +1| @else if false { } +2| @else { } + ---------< [#1 Insertion delimiter] = " " -[#2 Content] = 2:11-2:16 - >-----< -2| @else if false { } +[#2 Content] = 1:9-1:14 + >-----< +1| @else if false { } -[#2 Removal] = 2:11-2:17 - >------< -2| @else if false { } +[#2 Removal] = 1:9-1:15 + >------< +1| @else if false { } -[#2 Leading delimiter] = 2:10-2:11 - >-< -2| @else if false { } +[#2 Leading delimiter] = 1:8-1:9 + >-< +1| @else if false { } -[#2 Trailing delimiter] = 2:16-2:17 - >-< -2| @else if false { } +[#2 Trailing delimiter] = 1:14-1:15 + >-< +1| @else if false { } -[#2 Domain] = 2:2-2:20 - >------------------< -2| @else if false { } +[#2 Domain] = 1:0-1:18 + >------------------< +1| @else if false { } [#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/scss/ifStatement.scope b/data/fixtures/scopes/scss/ifStatement.scope index 871ca7512f..2f093485ec 100644 --- a/data/fixtures/scopes/scss/ifStatement.scope +++ b/data/fixtures/scopes/scss/ifStatement.scope @@ -1,28 +1,15 @@ -* { - @if true { } - @else if false { } - @else { } -} +@if true { } +@else if false { } +@else { } --- [Content] = -[Domain] = 1:2-3:11 - >------------ -1| @if true { } -2| @else if false { } -3| @else { } - -----------< - -[Removal] = 1:0-4:0 - >-------------- -1| @if true { } -2| @else if false { } -3| @else { } -4| } - < - -[Leading delimiter] = 1:0-1:2 - >--< -1| @if true { } +[Removal] = +[Domain] = 0:0-2:9 + >------------ +0| @if true { } +1| @else if false { } +2| @else { } + ---------< [Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/scss/interior.if.scope b/data/fixtures/scopes/scss/interior.if.scope index b6f883a0e1..3c64701f8f 100644 --- a/data/fixtures/scopes/scss/interior.if.scope +++ b/data/fixtures/scopes/scss/interior.if.scope @@ -1,133 +1,75 @@ -* { - @if true { } - @else if false { } - @else { } -} +@if true { } +@else if false { } +@else { } --- -[#1 Content] = 1:2-3:11 - >------------ -1| @if true { } -2| @else if false { } -3| @else { } - -----------< - -[#1 Removal] = 0:3-4:0 - > -0| * { -1| @if true { } -2| @else if false { } -3| @else { } -4| } - < - -[#1 Domain] = 0:0-4:1 - >--- -0| * { -1| @if true { } -2| @else if false { } -3| @else { } -4| } - -< +[#1 Content] = +[#1 Removal] = 0:10-0:11 + >-< +0| @if true { } + +[#1 Domain] = 0:0-0:12 + >------------< +0| @if true { } [#1 Insertion delimiter] = " " -[#2 Content] = 1:2-3:11 - >------------ -1| @if true { } -2| @else if false { } -3| @else { } - -----------< - -[#2 Removal] = 0:3-4:0 - > -0| * { -1| @if true { } -2| @else if false { } -3| @else { } -4| } - < - -[#2 Domain] = 0:2-4:1 - >- -0| * { -1| @if true { } -2| @else if false { } -3| @else { } -4| } - -< +[#2 Content] = +[#2 Removal] = 0:10-0:11 + >-< +0| @if true { } + +[#2 Domain] = 0:9-0:12 + >---< +0| @if true { } [#2 Insertion delimiter] = " " [#3 Content] = -[#3 Removal] = 1:12-1:13 - >-< -1| @if true { } +[#3 Removal] = 1:16-1:17 + >-< +1| @else if false { } -[#3 Domain] = 1:2-1:14 - >------------< -1| @if true { } +[#3 Domain] = 1:0-1:18 + >------------------< +1| @else if false { } [#3 Insertion delimiter] = " " [#4 Content] = -[#4 Removal] = 1:12-1:13 - >-< -1| @if true { } +[#4 Removal] = 1:16-1:17 + >-< +1| @else if false { } -[#4 Domain] = 1:11-1:14 - >---< -1| @if true { } +[#4 Domain] = 1:15-1:18 + >---< +1| @else if false { } [#4 Insertion delimiter] = " " [#5 Content] = -[#5 Removal] = 2:18-2:19 - >-< -2| @else if false { } +[#5 Removal] = 2:7-2:8 + >-< +2| @else { } -[#5 Domain] = 2:2-2:20 - >------------------< -2| @else if false { } +[#5 Domain] = 2:0-2:9 + >---------< +2| @else { } [#5 Insertion delimiter] = " " [#6 Content] = -[#6 Removal] = 2:18-2:19 - >-< -2| @else if false { } +[#6 Removal] = 2:7-2:8 + >-< +2| @else { } -[#6 Domain] = 2:17-2:20 - >---< -2| @else if false { } +[#6 Domain] = 2:6-2:9 + >---< +2| @else { } [#6 Insertion delimiter] = " " - - -[#7 Content] = -[#7 Removal] = 3:9-3:10 - >-< -3| @else { } - -[#7 Domain] = 3:2-3:11 - >---------< -3| @else { } - -[#7 Insertion delimiter] = " " - - -[#8 Content] = -[#8 Removal] = 3:9-3:10 - >-< -3| @else { } - -[#8 Domain] = 3:8-3:11 - >---< -3| @else { } - -[#8 Insertion delimiter] = " " diff --git a/queries/scss.scm b/queries/scss.scm index 4c78bab537..31d5225515 100644 --- a/queries/scss.scm +++ b/queries/scss.scm @@ -41,20 +41,29 @@ ;;!! @if true { } @else { } ;;! ^^^^^^^^^^^^^^^^^^^^^^^ -(if_statement) @ifStatement @branch.iteration - -;;!! @if true { } -;;! ^^^^^^^^^^^^ ;;! ^^^^ (if_statement (if_clause (condition) @condition - ) @branch @branch.removal.start.startOf @branch.removal.end.endOf + ) +) @ifStatement @branch.iteration @condition.domain + +;;!! @if true { } @else if false { } +;;! xxxxxxxxxxxxxxxxxxx +(if_statement + (if_clause) @branch @branch.removal.start.startOf (else_if_clause "if" @branch.removal.end.startOf - (#character-range! @branch.removal.start.startOf 1) - )? -) @condition.domain + ) + (#character-range! @branch.removal.start.startOf 1) +) + +;; Single if statement are else if. Remove range is content range. +(if_statement + (if_clause) @branch + (else_clause)? + . +) ;;!! @else false { } ;;! ^^^^^^^^^^^^^^^