mirror of
https://github.com/golang/go
synced 2024-11-05 18:16:10 -07:00
d926bd178c
Every package has a default type checking mode dictated by whether it's in the workspace or not. Some features force full rather than exported type checking, but AFAICT that ends up being more harm than good. For example, let's say we want to Find References on fmt.Printf in the stdlib. Before this CL, we'd force a new type check of the fmt package, then find no references because nothing else would have been checked against that new version. While there may be some features that work better in the current regime, I can't think of any, and we have no test coverage for them. So I'd rather start with what makes sense, and if we want to change it maybe let's write some tests. Change-Id: Iea589efb4b4374fd2a54451c868b6e2bd5484e20 Reviewed-on: https://go-review.googlesource.com/c/tools/+/248380 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
42 lines
915 B
Go
42 lines
915 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 TestNonWorkspaceReferences(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)
|
|
}
|
|
})
|
|
}
|