internal/lsp: add folding range for select case statements
This CL adds folding ranges for CommClause nodes (which represent select
statement cases).
Fixes golang/go#40146
Change-Id: Ifcc91cc43714d52346445fc02d9eee8b8364af20
Reviewed-on: https://go-review.googlesource.com/c/tools/+/245697
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/lsp/source/folding_range.go b/internal/lsp/source/folding_range.go
index 3ef8d64..1b7cea9 100644
--- a/internal/lsp/source/folding_range.go
+++ b/internal/lsp/source/folding_range.go
@@ -62,6 +62,9 @@
case *ast.CaseClause:
// Fold from position of ":" to end.
start, end = n.Colon+1, n.End()
+ case *ast.CommClause:
+ // Fold from position of ":" to end.
+ start, end = n.Colon+1, n.End()
case *ast.CallExpr:
// Fold from position of "(" to position of ")".
start, end = n.Lparen+1, n.Rparen
@@ -117,6 +120,9 @@
case *ast.CaseClause:
// Fold from position of ":" to end.
start, end = n.Colon+1, n.End()
+ case *ast.CommClause:
+ // Fold from position of ":" to end.
+ start, end = n.Colon+1, n.End()
case *ast.FieldList:
// Fold lines between opening parenthesis/brace and closing parenthesis/brace.
if !n.Opening.IsValid() || !n.Closing.IsValid() {
diff --git a/internal/lsp/testdata/lsp/primarymod/folding/a.go b/internal/lsp/testdata/lsp/primarymod/folding/a.go
index 43f54d5..e472a33 100644
--- a/internal/lsp/testdata/lsp/primarymod/folding/a.go
+++ b/internal/lsp/testdata/lsp/primarymod/folding/a.go
@@ -44,6 +44,19 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {
+ fmt.Println("true from x")
+ } else {
+ fmt.Println("false from x")
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment
// that is not a doc comment.
return `
diff --git a/internal/lsp/testdata/lsp/primarymod/folding/a.go.golden b/internal/lsp/testdata/lsp/primarymod/folding/a.go.golden
index 2b97014..6f71e1c 100644
--- a/internal/lsp/testdata/lsp/primarymod/folding/a.go.golden
+++ b/internal/lsp/testdata/lsp/primarymod/folding/a.go.golden
@@ -27,6 +27,8 @@
_ = map[string]int{<>}
type T struct {<>}
_ = T{<>}
+ x, y := make(<>), make(<>)
+ select {<>}
// This is a multiline comment<>
return `
this string
@@ -73,6 +75,12 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:<>
+ case <-y:<>
+ default:<>
+ }
// This is a multiline comment
// that is not a doc comment.
return `
@@ -123,6 +131,15 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {<>} else {<>}
+ case <-y:
+ fmt.Println(<>)
+ default:
+ fmt.Println(<>)
+ }
// This is a multiline comment
// that is not a doc comment.
return `
@@ -177,6 +194,19 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {
+ fmt.Println(<>)
+ } else {
+ fmt.Println(<>)
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment
// that is not a doc comment.
return `
@@ -188,7 +218,7 @@
3:9-6:0
10:22-11:32
12:10-12:9
-12:20-52:0
+12:20-65:0
13:10-24:1
14:12-19:3
15:12-17:2
@@ -204,7 +234,19 @@
32:21-36:1
37:17-41:1
42:8-46:1
-47:32-48:30
+47:15-47:23
+47:32-47:40
+48:10-59:1
+49:18-54:3
+50:11-52:2
+51:16-51:28
+52:11-54:2
+53:16-53:29
+55:11-56:18
+56:15-56:17
+57:10-58:24
+58:15-58:23
+60:32-61:30
-- foldingRange-comment-0 --
package folding //@fold("package")
@@ -252,6 +294,19 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {
+ fmt.Println("true from x")
+ } else {
+ fmt.Println("false from x")
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment<>
return `
this string
@@ -302,6 +357,19 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {
+ fmt.Println("true from x")
+ } else {
+ fmt.Println("false from x")
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment
// that is not a doc comment.
return `
@@ -345,6 +413,9 @@
}
_ = T{<>,
}
+ x, y := make(chan bool), make(chan bool)
+ select {<>
+ }
// This is a multiline comment<>
return `
this string
@@ -391,6 +462,12 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:<>
+ case <-y:<>
+ default:<>
+ }
// This is a multiline comment
// that is not a doc comment.
return `
@@ -443,6 +520,17 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {<>
+ } else {<>
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment
// that is not a doc comment.
return `
@@ -496,6 +584,19 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {
+ fmt.Println("true from x")
+ } else {
+ fmt.Println("false from x")
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment<>
return `
this string
@@ -547,6 +648,19 @@
g: 4,
h: "i",
}
+ x, y := make(chan bool), make(chan bool)
+ select {
+ case val := <-x:
+ if val {
+ fmt.Println("true from x")
+ } else {
+ fmt.Println("false from x")
+ }
+ case <-y:
+ fmt.Println("y")
+ default:
+ fmt.Println("default")
+ }
// This is a multiline comment
// that is not a doc comment.
return `