aboutsummaryrefslogtreecommitdiff
path: root/gopls/internal/lsp/testdata/references/refs.go
blob: e7ff50494305ac6fc5e96c0e689cae611b9cb5a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Package refs is a package used to test find references.
package refs

import "os" //@mark(osDecl, `"os"`),refs("os", osDecl, osUse)

type i int //@mark(typeI, "i"),refs("i", typeI, argI, returnI, embeddedI)

type X struct {
	Y int //@mark(typeXY, "Y")
}

func _(_ i) []bool { //@mark(argI, "i")
	return nil
}

func _(_ []byte) i { //@mark(returnI, "i")
	return 0
}

var q string //@mark(declQ, "q"),refs("q", declQ, assignQ, bobQ)

var Q string //@mark(declExpQ, "Q"),refs("Q", declExpQ, assignExpQ, bobExpQ)

func _() {
	q = "hello" //@mark(assignQ, "q")
	bob := func(_ string) {}
	bob(q) //@mark(bobQ, "q")
}

type e struct {
	i //@mark(embeddedI, "i"),refs("i", embeddedI, embeddedIUse)
}

func _() {
	_ = e{}.i //@mark(embeddedIUse, "i")
}

const (
	foo = iota //@refs("iota")
)

func _(x interface{}) {
	// We use the _ prefix because the markers inhabit a single
	// namespace and yDecl is already used in ../highlights/highlights.go.
	switch _y := x.(type) { //@mark(_yDecl, "_y"),refs("_y", _yDecl, _yInt, _yDefault)
	case int:
		println(_y) //@mark(_yInt, "_y"),refs("_y", _yDecl, _yInt, _yDefault)
	default:
		println(_y) //@mark(_yDefault, "_y")
	}

	os.Getwd() //@mark(osUse, "os")
}