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/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..179a61ee28 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -251,37 +251,43 @@ "}" @interior.end.startOf @branch.iteration.end.startOf @condition.iteration.end.startOf ) @value.domain -;; The outermost if statement +;;!! if () {} else {} ( (if_statement) @ifStatement @statement @branch.iteration (#not-parent-type? @ifStatement if_statement) ) -;; first if in an if-else chain +;;!! if () {} ( (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 " ") + (#shrink-to-match! @condition "^\\(?(?[^)]*)\\)?$") ) -;; internal if in an if-else chain +;;!! else if () {} (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 " ") + (#shrink-to-match! @condition "^\\(?(?[^)]*)\\)?$") ) -;; 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 " ") ) [ @@ -356,23 +362,6 @@ result: (_) @type ) @_.domain -;;!! if true {} -( - (_ - condition: (_) @condition - ) @_.domain - (#not-type? @condition parenthesized_expression) - (#not-type? @_.domain for_clause) -) - -;;!! if (true) {} -( - (_ - condition: (parenthesized_expression) @condition - ) @_.domain - (#child-range! @condition 0 -1 true true) -) - ;;!! for i := 0; i < size; i++ {} ;;! ^^^^^^^^ (for_statement