Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/fixtures/recorded/languages/go/chuckBranch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 2 additions & 2 deletions data/fixtures/scopes/go/branch/branch.if.elif.else.scope
Original file line number Diff line number Diff line change
Expand Up @@ -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
>-<
Expand Down
5 changes: 2 additions & 3 deletions data/fixtures/scopes/go/condition/condition.if.scope
Original file line number Diff line number Diff line change
Expand Up @@ -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] = " "
55 changes: 22 additions & 33 deletions queries/go.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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 "^\\(?(?<keep>[^)]*)\\)?$")
)

;; 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 "^\\(?(?<keep>[^)]*)\\)?$")
)

;; 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 " ")
)

[
Expand Down Expand Up @@ -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
Expand Down
Loading