From 35104abee33967c52bdced891e50c966d766d232 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 14:29:38 +0100 Subject: [PATCH 1/4] Update go if scope --- .../go/branch/branch.if.elif.else.scope | 4 +- .../scopes/go/condition/condition.if.scope | 5 +-- queries/go.scm | 38 ++++++++++--------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/data/fixtures/scopes/go/branch/branch.if.elif.else.scope b/data/fixtures/scopes/go/branch/branch.if.elif.else.scope index 1f5f5582b6..2b26dd9284 100644 --- a/data/fixtures/scopes/go/branch/branch.if.elif.else.scope +++ b/data/fixtures/scopes/go/branch/branch.if.elif.else.scope @@ -11,11 +11,11 @@ if true { 1| } else if false { -< -[#1 Removal] = 0:0-1:2 +[#1 Removal] = 0:0-1:7 >--------- 0| if true { 1| } else if false { - --< + -------< [#1 Trailing delimiter] = 1:1-1:2 >-< diff --git a/data/fixtures/scopes/go/condition/condition.if.scope b/data/fixtures/scopes/go/condition/condition.if.scope index 0b2a84f7bc..7249731ded 100644 --- a/data/fixtures/scopes/go/condition/condition.if.scope +++ b/data/fixtures/scopes/go/condition/condition.if.scope @@ -47,11 +47,10 @@ if true { >-< 1| } else if false { -[#2 Domain] = 1:7-3:1 - >---------- +[#2 Domain] = 1:2-2:1 + >--------------- 1| } else if false { 2| } else { -3| } -< [#2 Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 31f9ffe65c..3479b935ec 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -251,37 +251,41 @@ "}" @interior.end.startOf @branch.iteration.end.startOf @condition.iteration.end.startOf ) @value.domain -;; The outermost if statement +;;!! if true {} else {} ( (if_statement) @ifStatement @statement @branch.iteration (#not-parent-type? @ifStatement if_statement) ) -;; first if in an if-else chain +;;!! if true {} ( (if_statement - consequence: (block) @branch.end.endOf - ) @branch.start.startOf - (#not-parent-type? @branch.start.startOf if_statement) - (#insertion-delimiter! @branch.start.startOf " ") + "if" @branch.start @branch.removal.start + condition: (_) @condition + consequence: (_) @branch.end @branch.removal.end + "else"? @branch.removal.end.startOf + alternative: (if_statement)? @branch.removal.end.startOf + ) @condition.domain + (#not-parent-type? @condition.domain if_statement) + (#insertion-delimiter! @branch.start " ") ) -;; internal if in an if-else chain +;;!! else if true {} (if_statement - "else" @branch.start + "else" @branch.start @condition.domain.start alternative: (if_statement - consequence: (block) @branch.end + condition: (_) @condition + consequence: (_) @branch.end @condition.domain.end ) (#insertion-delimiter! @branch.start " ") ) -;; final else branch in an if-else chain -( - (if_statement - "else" @branch.start.startOf - alternative: (block) - ) @branch.end.endOf - (#insertion-delimiter! @branch.start.startOf " ") +;;!! else {} + +(if_statement + "else" @branch.start + alternative: (block) @branch.end + (#insertion-delimiter! @branch.start " ") ) [ @@ -362,7 +366,7 @@ condition: (_) @condition ) @_.domain (#not-type? @condition parenthesized_expression) - (#not-type? @_.domain for_clause) + (#not-type? @_.domain for_clause if_statement) ) ;;!! if (true) {} From 424fd0caf5442c2fa4c5e44c0795f4683f505957 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 15:31:52 +0100 Subject: [PATCH 2/4] Update test --- data/fixtures/recorded/languages/go/chuckBranch.yml | 2 +- queries/go.scm | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/data/fixtures/recorded/languages/go/chuckBranch.yml b/data/fixtures/recorded/languages/go/chuckBranch.yml index 3f6d79c1ef..5d05f2ad89 100644 --- a/data/fixtures/recorded/languages/go/chuckBranch.yml +++ b/data/fixtures/recorded/languages/go/chuckBranch.yml @@ -17,7 +17,7 @@ initialState: active: {line: 0, character: 0} marks: {} finalState: - documentContents: "else if y {\n\ty++\n} else {\n\tx--\n}" + documentContents: "if y {\n\ty++\n} else {\n\tx--\n}" selections: - anchor: {line: 0, character: 0} active: {line: 0, character: 0} diff --git a/queries/go.scm b/queries/go.scm index 3479b935ec..5be6b3a71f 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -360,15 +360,6 @@ result: (_) @type ) @_.domain -;;!! if true {} -( - (_ - condition: (_) @condition - ) @_.domain - (#not-type? @condition parenthesized_expression) - (#not-type? @_.domain for_clause if_statement) -) - ;;!! if (true) {} ( (_ From 5c1c72d3efedad5add44582adb58e732bbfa4df6 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 15:53:55 +0100 Subject: [PATCH 3/4] Better handling off parameterized expression condition --- queries/go.scm | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/queries/go.scm b/queries/go.scm index 5be6b3a71f..c766e2b345 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -268,6 +268,7 @@ ) @condition.domain (#not-parent-type? @condition.domain if_statement) (#insertion-delimiter! @branch.start " ") + (#shrink-to-match! @condition "^\\(?(?[^)]*)\\)?$") ) ;;!! else if true {} @@ -278,6 +279,7 @@ consequence: (_) @branch.end @condition.domain.end ) (#insertion-delimiter! @branch.start " ") + (#shrink-to-match! @condition "^\\(?(?[^)]*)\\)?$") ) ;;!! else {} @@ -360,14 +362,6 @@ result: (_) @type ) @_.domain -;;!! if (true) {} -( - (_ - condition: (parenthesized_expression) @condition - ) @_.domain - (#child-range! @condition 0 -1 true true) -) - ;;!! for i := 0; i < size; i++ {} ;;! ^^^^^^^^ (for_statement From bd8b833db332e63db09de974423c453eb248e603 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 15:58:15 +0100 Subject: [PATCH 4/4] Update comments --- queries/go.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/queries/go.scm b/queries/go.scm index c766e2b345..179a61ee28 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -251,13 +251,13 @@ "}" @interior.end.startOf @branch.iteration.end.startOf @condition.iteration.end.startOf ) @value.domain -;;!! if true {} else {} +;;!! if () {} else {} ( (if_statement) @ifStatement @statement @branch.iteration (#not-parent-type? @ifStatement if_statement) ) -;;!! if true {} +;;!! if () {} ( (if_statement "if" @branch.start @branch.removal.start @@ -271,7 +271,7 @@ (#shrink-to-match! @condition "^\\(?(?[^)]*)\\)?$") ) -;;!! else if true {} +;;!! else if () {} (if_statement "else" @branch.start @condition.domain.start alternative: (if_statement