diff options
Diffstat (limited to 'gopls/internal/lsp/testdata/references')
5 files changed, 129 insertions, 0 deletions
diff --git a/gopls/internal/lsp/testdata/references/another/another.go b/gopls/internal/lsp/testdata/references/another/another.go new file mode 100644 index 000000000..20e3ebca1 --- /dev/null +++ b/gopls/internal/lsp/testdata/references/another/another.go @@ -0,0 +1,13 @@ +// Package another has another type. +package another + +import ( + other "golang.org/lsptests/references/other" +) + +func _() { + xes := other.GetXes() + for _, x := range xes { //@mark(defX, "x") + _ = x.Y //@mark(useX, "x"),mark(anotherXY, "Y"),refs("Y", typeXY, anotherXY, GetXesY),refs(".", defX, useX),refs("x", defX, useX) + } +} diff --git a/gopls/internal/lsp/testdata/references/interfaces/interfaces.go b/gopls/internal/lsp/testdata/references/interfaces/interfaces.go new file mode 100644 index 000000000..6661dcc5d --- /dev/null +++ b/gopls/internal/lsp/testdata/references/interfaces/interfaces.go @@ -0,0 +1,34 @@ +package interfaces + +type first interface { + common() //@mark(firCommon, "common"),refs("common", firCommon, xCommon, zCommon) + firstMethod() //@mark(firMethod, "firstMethod"),refs("firstMethod", firMethod, xfMethod, zfMethod) +} + +type second interface { + common() //@mark(secCommon, "common"),refs("common", secCommon, yCommon, zCommon) + secondMethod() //@mark(secMethod, "secondMethod"),refs("secondMethod", secMethod, ysMethod, zsMethod) +} + +type s struct {} + +func (*s) common() {} //@mark(sCommon, "common"),refs("common", sCommon, xCommon, yCommon, zCommon) + +func (*s) firstMethod() {} //@mark(sfMethod, "firstMethod"),refs("firstMethod", sfMethod, xfMethod, zfMethod) + +func (*s) secondMethod() {} //@mark(ssMethod, "secondMethod"),refs("secondMethod", ssMethod, ysMethod, zsMethod) + +func main() { + var x first = &s{} + var y second = &s{} + + x.common() //@mark(xCommon, "common"),refs("common", firCommon, xCommon, zCommon) + x.firstMethod() //@mark(xfMethod, "firstMethod"),refs("firstMethod", firMethod, xfMethod, zfMethod) + y.common() //@mark(yCommon, "common"),refs("common", secCommon, yCommon, zCommon) + y.secondMethod() //@mark(ysMethod, "secondMethod"),refs("secondMethod", secMethod, ysMethod, zsMethod) + + var z *s = &s{} + z.firstMethod() //@mark(zfMethod, "firstMethod"),refs("firstMethod", sfMethod, xfMethod, zfMethod) + z.secondMethod() //@mark(zsMethod, "secondMethod"),refs("secondMethod", ssMethod, ysMethod, zsMethod) + z.common() //@mark(zCommon, "common"),refs("common", sCommon, xCommon, yCommon, zCommon) +} diff --git a/gopls/internal/lsp/testdata/references/other/other.go b/gopls/internal/lsp/testdata/references/other/other.go new file mode 100644 index 000000000..daac1a028 --- /dev/null +++ b/gopls/internal/lsp/testdata/references/other/other.go @@ -0,0 +1,19 @@ +package other + +import ( + references "golang.org/lsptests/references" +) + +func GetXes() []references.X { + return []references.X{ + { + Y: 1, //@mark(GetXesY, "Y"),refs("Y", typeXY, GetXesY, anotherXY) + }, + } +} + +func _() { + references.Q = "hello" //@mark(assignExpQ, "Q") + bob := func(_ string) {} + bob(references.Q) //@mark(bobExpQ, "Q") +} diff --git a/gopls/internal/lsp/testdata/references/refs.go b/gopls/internal/lsp/testdata/references/refs.go new file mode 100644 index 000000000..e7ff50494 --- /dev/null +++ b/gopls/internal/lsp/testdata/references/refs.go @@ -0,0 +1,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") +} diff --git a/gopls/internal/lsp/testdata/references/refs_test.go b/gopls/internal/lsp/testdata/references/refs_test.go new file mode 100644 index 000000000..08c0db1f0 --- /dev/null +++ b/gopls/internal/lsp/testdata/references/refs_test.go @@ -0,0 +1,10 @@ +package references + +import ( + "testing" +) + +// This test exists to bring the test package into existence. + +func TestReferences(t *testing.T) { +} |