gotools/gopls/internal/test/marker/testdata/foldingrange/a.txt

This test checks basic behavior of textDocument/foldingRange.

-- a.go --
package folding //@foldingrange(raw)

import (
	"fmt"
	_ "log"
	"sort"
	"time"
)

import _ "os"

// bar is a function.
// With a multiline doc comment.
func bar() (
	string,
) {
	/* This is a single line comment */
	switch {
	case true:
		if true {
			fmt.Println("true")
		} else {
			fmt.Println("false")
		}
	case false:
		fmt.Println("false")
	default:
		fmt.Println("default")
	}
	/* This is a multiline
	block
	comment */

	/* This is a multiline
	block
	comment */
	// Followed by another comment.
	_ = []int{
		1,
		2,
		3,
	}
	_ = [2]string{"d",
		"e",
	}
	_ = map[string]int{
		"a": 1,
		"b": 2,
		"c": 3,
	}
	type T struct {
		f string
		g int
		h string
	}
	_ = T{
		f: "j",
		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 `
this string
is not indented`
}

func _() {
	slice := []int{1, 2, 3}
	sort.Slice(slice, func(i, j int) bool {
		a, b := slice[i], slice[j]
		return a < b
	})

	sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })

	sort.Slice(
		slice,
		func(i, j int) bool {
			return slice[i] < slice[j]
		},
	)

	fmt.Println(
		1, 2, 3,
		4,
	)

	fmt.Println(1, 2, 3,
		4, 5, 6,
		7, 8, 9,
		10)

	// Call with ellipsis.
	_ = fmt.Errorf(
		"test %d %d",
		[]any{1, 2, 3}...,
	)

	// Check multiline string.
	fmt.Println(
		`multi
		line
		string
		`,
		1, 2, 3,
	)

	// Call without arguments.
	_ = time.Now()
}

func _(
	a int, b int,
	c int,
) {
}
-- @raw --
package folding //@foldingrange(raw)

import (<0 kind="imports">
	"fmt"
	_ "log"
	"sort"
	"time"
</0>)

import _ "os"

// bar is a function.<1 kind="comment">
// With a multiline doc comment.</1>
func bar() (<2 kind="">
	string,
</2>) {<3 kind="">
	/* This is a single line comment */
	switch {<4 kind="">
	case true:<5 kind="">
		if true {<6 kind="">
			fmt.Println(<7 kind="">"true"</7>)
		</6>} else {<8 kind="">
			fmt.Println(<9 kind="">"false"</9>)
		</8>}</5>
	case false:<10 kind="">
		fmt.Println(<11 kind="">"false"</11>)</10>
	default:<12 kind="">
		fmt.Println(<13 kind="">"default"</13>)</12>
	</4>}
	/* This is a multiline<14 kind="comment">
	block
	comment */</14>

	/* This is a multiline<15 kind="comment">
	block
	comment */
	// Followed by another comment.</15>
	_ = []int{<16 kind="">
		1,
		2,
		3,
	</16>}
	_ = [2]string{<17 kind="">"d",
		"e",
	</17>}
	_ = map[string]int{<18 kind="">
		"a": 1,
		"b": 2,
		"c": 3,
	</18>}
	type T struct {<19 kind="">
		f string
		g int
		h string
	</19>}
	_ = T{<20 kind="">
		f: "j",
		g: 4,
		h: "i",
	</20>}
	x, y := make(<21 kind="">chan bool</21>), make(<22 kind="">chan bool</22>)
	select {<23 kind="">
	case val := <-x:<24 kind="">
		if val {<25 kind="">
			fmt.Println(<26 kind="">"true from x"</26>)
		</25>} else {<27 kind="">
			fmt.Println(<28 kind="">"false from x"</28>)
		</27>}</24>
	case <-y:<29 kind="">
		fmt.Println(<30 kind="">"y"</30>)</29>
	default:<31 kind="">
		fmt.Println(<32 kind="">"default"</32>)</31>
	</23>}
	// This is a multiline comment<33 kind="comment">
	// that is not a doc comment.</33>
	return <34 kind="">`
this string
is not indented`</34>
</3>}

func _() {<35 kind="">
	slice := []int{<36 kind="">1, 2, 3</36>}
	sort.Slice(<37 kind="">slice, func(<38 kind="">i, j int</38>) bool {<39 kind="">
		a, b := slice[i], slice[j]
		return a < b
	</39>}</37>)

	sort.Slice(<40 kind="">slice, func(<41 kind="">i, j int</41>) bool {<42 kind=""> return slice[i] < slice[j] </42>}</40>)

	sort.Slice(<43 kind="">
		slice,
		func(<44 kind="">i, j int</44>) bool {<45 kind="">
			return slice[i] < slice[j]
		</45>},
	</43>)

	fmt.Println(<46 kind="">
		1, 2, 3,
		4,
	</46>)

	fmt.Println(<47 kind="">1, 2, 3,
		4, 5, 6,
		7, 8, 9,
		10</47>)

	// Call with ellipsis.
	_ = fmt.Errorf(<48 kind="">
		"test %d %d",
		[]any{<49 kind="">1, 2, 3</49>}...,
	</48>)

	// Check multiline string.
	fmt.Println(<50 kind="">
		<51 kind="">`multi
		line
		string
		`</51>,
		1, 2, 3,
	</50>)

	// Call without arguments.
	_ = time.Now()
</35>}

func _(<52 kind="">
	a int, b int,
	c int,
</52>) {<53 kind="">
</53>}