mirror of
https://github.com/golang/go
synced 2024-11-05 11:46:12 -07:00
d94536333c
CL 248380 forced all type checking to be in the default workspace mode. In that CL, I said I couldn't think of any features that would break. It appears I didn't think very hard. Navigation features inside of dependencies are something I use all the time and they broke. Reintroduce the ability to get packages in a particular mode, and make it convenient to get them in all relevant modes. Update some critical features to do so, and add regression tests. Fixes golang/go#40809. Change-Id: I96279f4ff994203694629ea872795246c410b206 Reviewed-on: https://go-review.googlesource.com/c/tools/+/249120 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
42 lines
909 B
Go
42 lines
909 B
Go
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package regtest
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestStdlibReferences(t *testing.T) {
|
|
const files = `
|
|
-- go.mod --
|
|
module mod.com
|
|
|
|
-- main.go --
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Print()
|
|
}
|
|
`
|
|
|
|
run(t, files, func(t *testing.T, env *Env) {
|
|
env.OpenFile("main.go")
|
|
file, pos := env.GoToDefinition("main.go", env.RegexpSearch("main.go", `fmt.(Print)`))
|
|
refs, err := env.Editor.References(env.Ctx, file, pos)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(refs) != 2 {
|
|
t.Fatalf("got %v reference(s), want 2", len(refs))
|
|
}
|
|
// The first reference is guaranteed to be the definition.
|
|
if got, want := refs[1].URI, env.Sandbox.Workdir.URI("main.go"); got != want {
|
|
t.Errorf("found reference in %v, wanted %v", got, want)
|
|
}
|
|
})
|
|
}
|