| 1 |
This test checks basic behavior of textDocument/foldingRange. |
| 2 |
|
| 3 |
-- a.go -- |
| 4 |
package folding //@foldingrange(raw) |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
_ "log" |
| 9 |
"sort" |
| 10 |
"time" |
| 11 |
) |
| 12 |
|
| 13 |
import _ "os" |
| 14 |
|
| 15 |
// Bar is a function. |
| 16 |
// With a multiline doc comment. |
| 17 |
func Bar() ( |
| 18 |
string, |
| 19 |
) { |
| 20 |
/* This is a single line comment */ |
| 21 |
switch { |
| 22 |
case true: |
| 23 |
if true { |
| 24 |
fmt.Println("true") |
| 25 |
} else { |
| 26 |
fmt.Println("false") |
| 27 |
} |
| 28 |
case false: |
| 29 |
fmt.Println("false") |
| 30 |
default: |
| 31 |
fmt.Println("default") |
| 32 |
} |
| 33 |
/* This is a multiline |
| 34 |
block |
| 35 |
comment */ |
| 36 |
|
| 37 |
/* This is a multiline |
| 38 |
block |
| 39 |
comment */ |
| 40 |
// Followed by another comment. |
| 41 |
_ = []int{ |
| 42 |
1, |
| 43 |
2, |
| 44 |
3, |
| 45 |
} |
| 46 |
_ = [2]string{"d", |
| 47 |
"e", |
| 48 |
} |
| 49 |
_ = map[string]int{ |
| 50 |
"a": 1, |
| 51 |
"b": 2, |
| 52 |
"c": 3, |
| 53 |
} |
| 54 |
type T struct { |
| 55 |
f string |
| 56 |
g int |
| 57 |
h string |
| 58 |
} |
| 59 |
_ = T{ |
| 60 |
f: "j", |
| 61 |
g: 4, |
| 62 |
h: "i", |
| 63 |
} |
| 64 |
x, y := make(chan bool), make(chan bool) |
| 65 |
select { |
| 66 |
case val := <-x: |
| 67 |
if val { |
| 68 |
fmt.Println("true from x") |
| 69 |
} else { |
| 70 |
fmt.Println("false from x") |
| 71 |
} |
| 72 |
case <-y: |
| 73 |
fmt.Println("y") |
| 74 |
default: |
| 75 |
fmt.Println("default") |
| 76 |
} |
| 77 |
// This is a multiline comment |
| 78 |
// that is not a doc comment. |
| 79 |
return ` |
| 80 |
this string |
| 81 |
is not indented` |
| 82 |
} |
| 83 |
|
| 84 |
func _() { |
| 85 |
slice := []int{1, 2, 3} |
| 86 |
sort.Slice(slice, func(i, j int) bool { |
| 87 |
a, b := slice[i], slice[j] |
| 88 |
return a > b |
| 89 |
}) |
| 90 |
|
| 91 |
sort.Slice(slice, func(i, j int) bool { return slice[i] > slice[j] }) |
| 92 |
|
| 93 |
sort.Slice( |
| 94 |
slice, |
| 95 |
func(i, j int) bool { |
| 96 |
return slice[i] > slice[j] |
| 97 |
}, |
| 98 |
) |
| 99 |
|
| 100 |
fmt.Println( |
| 101 |
1, 2, 3, |
| 102 |
4, |
| 103 |
) |
| 104 |
|
| 105 |
fmt.Println(1, 2, 3, |
| 106 |
4, 5, 6, |
| 107 |
7, 8, 9, |
| 108 |
10) |
| 109 |
|
| 110 |
// Call with ellipsis. |
| 111 |
_ = fmt.Errorf( |
| 112 |
"test %d %d", |
| 113 |
[]any{1, 2, 3}..., |
| 114 |
) |
| 115 |
|
| 116 |
// Check multiline string. |
| 117 |
fmt.Println( |
| 118 |
`multi |
| 119 |
line |
| 120 |
string |
| 121 |
`, |
| 122 |
1, 2, 3, |
| 123 |
) |
| 124 |
|
| 125 |
// Call without arguments. |
| 126 |
_ = time.Now() |
| 127 |
} |
| 128 |
|
| 129 |
func _( |
| 130 |
a int, b int, |
| 131 |
c int, |
| 132 |
) { |
| 133 |
} |
| 134 |
|
| 135 |
func _() { // comment |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
-- @raw -- |
| 140 |
package folding //@foldingrange(raw) |
| 141 |
|
| 142 |
import (<0 kind="imports"> |
| 143 |
"fmt" |
| 144 |
_ "log" |
| 145 |
"sort" |
| 146 |
"time" |
| 147 |
</0>) |
| 148 |
|
| 149 |
import _ "os" |
| 150 |
|
| 151 |
// Bar is a function.<1 kind="comment"> |
| 152 |
// With a multiline doc comment.</1> |
| 153 |
func Bar() (<2 kind=""> |
| 154 |
string, |
| 155 |
</2>) {<3 kind=""> |
| 156 |
/* This is a single line comment */ |
| 157 |
switch {<4 kind=""> |
| 158 |
case true:<5 kind=""> |
| 159 |
if true {<6 kind=""> |
| 160 |
fmt.Println(<7 kind="">"true"</7>) |
| 161 |
</6>} else {<8 kind=""> |
| 162 |
fmt.Println(<9 kind="">"false"</9>) |
| 163 |
</8>}</5> |
| 164 |
case false:<10 kind=""> |
| 165 |
fmt.Println(<11 kind="">"false"</11>)</10> |
| 166 |
default:<12 kind=""> |
| 167 |
fmt.Println(<13 kind="">"default"</13>)</12> |
| 168 |
</4>} |
| 169 |
/* This is a multiline<14 kind="comment"> |
| 170 |
block |
| 171 |
comment */</14> |
| 172 |
|
| 173 |
/* This is a multiline<15 kind="comment"> |
| 174 |
block |
| 175 |
comment */ |
| 176 |
// Followed by another comment.</15> |
| 177 |
_ = []int{<16 kind=""> |
| 178 |
1, |
| 179 |
2, |
| 180 |
3, |
| 181 |
</16>} |
| 182 |
_ = [2]string{<17 kind="">"d", |
| 183 |
"e", |
| 184 |
</17>} |
| 185 |
_ = map[string]int{<18 kind=""> |
| 186 |
"a": 1, |
| 187 |
"b": 2, |
| 188 |
"c": 3, |
| 189 |
</18>} |
| 190 |
type T struct {<19 kind=""> |
| 191 |
f string |
| 192 |
g int |
| 193 |
h string |
| 194 |
</19>} |
| 195 |
_ = T{<20 kind=""> |
| 196 |
f: "j", |
| 197 |
g: 4, |
| 198 |
h: "i", |
| 199 |
</20>} |
| 200 |
x, y := make(<21 kind="">chan bool</21>), make(<22 kind="">chan bool</22>) |
| 201 |
select {<23 kind=""> |
| 202 |
case val := <-x:<24 kind=""> |
| 203 |
if val {<25 kind=""> |
| 204 |
fmt.Println(<26 kind="">"true from x"</26>) |
| 205 |
</25>} else {<27 kind=""> |
| 206 |
fmt.Println(<28 kind="">"false from x"</28>) |
| 207 |
</27>}</24> |
| 208 |
case <-y:<29 kind=""> |
| 209 |
fmt.Println(<30 kind="">"y"</30>)</29> |
| 210 |
default:<31 kind=""> |
| 211 |
fmt.Println(<32 kind="">"default"</32>)</31> |
| 212 |
</23>} |
| 213 |
// This is a multiline comment<33 kind="comment"> |
| 214 |
// that is not a doc comment.</33> |
| 215 |
return <34 kind="">` |
| 216 |
this string |
| 217 |
is not indented`</34> |
| 218 |
</3>} |
| 219 |
|
| 220 |
func _() {<35 kind=""> |
| 221 |
slice := []int{<36 kind="">1, 2, 3</36>} |
| 222 |
sort.Slice(<37 kind="">slice, func(<38 kind="">i, j int</38>) bool {<39 kind=""> |
| 223 |
a, b := slice[i], slice[j] |
| 224 |
return a > b |
| 225 |
</39>}</37>) |
| 226 |
|
| 227 |
sort.Slice(<40 kind="">slice, func(<41 kind="">i, j int</41>) bool {<42 kind=""> return slice[i] > slice[j] </42>}</40>) |
| 228 |
|
| 229 |
sort.Slice(<43 kind=""> |
| 230 |
slice, |
| 231 |
func(<44 kind="">i, j int</44>) bool {<45 kind=""> |
| 232 |
return slice[i] > slice[j] |
| 233 |
</45>}, |
| 234 |
</43>) |
| 235 |
|
| 236 |
fmt.Println(<46 kind=""> |
| 237 |
1, 2, 3, |
| 238 |
4, |
| 239 |
</46>) |
| 240 |
|
| 241 |
fmt.Println(<47 kind="">1, 2, 3, |
| 242 |
4, 5, 6, |
| 243 |
7, 8, 9, |
| 244 |
10</47>) |
| 245 |
|
| 246 |
// Call with ellipsis. |
| 247 |
_ = fmt.Errorf(<48 kind=""> |
| 248 |
"test %d %d", |
| 249 |
[]any{<49 kind="">1, 2, 3</49>}..., |
| 250 |
</48>) |
| 251 |
|
| 252 |
// Check multiline string. |
| 253 |
fmt.Println(<50 kind=""> |
| 254 |
<51 kind="">`multi |
| 255 |
line |
| 256 |
string |
| 257 |
`</51>, |
| 258 |
1, 2, 3, |
| 259 |
</50>) |
| 260 |
|
| 261 |
// Call without arguments. |
| 262 |
_ = time.Now() |
| 263 |
</35>} |
| 264 |
|
| 265 |
func _(<52 kind=""> |
| 266 |
a int, b int, |
| 267 |
c int, |
| 268 |
</52>) {<53 kind=""> |
| 269 |
</53>} |
| 270 |
|
| 271 |
func _() {<54 kind=""> // comment |
| 272 |
|
| 273 |
</54>} |
| 274 |
|