mirror of
https://github.com/golang/go
synced 2024-11-05 17:06:13 -07:00
4d5ea46c79
In addition to adding a `go mod vendor` command option, which can be exposed via an editor client frontend, we show a suggestion to users who experience the "inconsistent vendoring" error message. The main change made here is that we save the view initialization error, and we return it if the view has absolutely no metadata. This seems reasonable enough, but my fear is that it may lead to us showing outdated error messages. I will spend some time improving the handling of initialization errors in follow-up CLs. Updates golang/go#39100 Change-Id: Iba21fb3fbfa4bca956fdf63736b397c47fc7ae44 Reviewed-on: https://go-review.googlesource.com/c/tools/+/235619 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package regtest
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp"
|
|
"golang.org/x/tools/internal/testenv"
|
|
)
|
|
|
|
const basicProxy = `
|
|
-- golang.org/x/hello@v1.2.3/go.mod --
|
|
module golang.org/x/hello
|
|
|
|
go 1.14
|
|
-- golang.org/x/hello@v1.2.3/hi/hi.go --
|
|
package hi
|
|
|
|
var Goodbye error
|
|
`
|
|
|
|
func TestInconsistentVendoring(t *testing.T) {
|
|
testenv.NeedsGo1Point(t, 14)
|
|
const pkgThatUsesVendoring = `
|
|
-- go.mod --
|
|
module mod.com
|
|
|
|
go 1.14
|
|
|
|
require golang.org/x/hello v1.2.3
|
|
-- vendor/modules.txt --
|
|
-- a/a1.go --
|
|
package a
|
|
|
|
import "golang.org/x/hello/hi"
|
|
|
|
func _() {
|
|
_ = hi.Goodbye
|
|
var q int // hardcode a diagnostic
|
|
}
|
|
`
|
|
runner.Run(t, pkgThatUsesVendoring, func(t *testing.T, env *Env) {
|
|
env.OpenFile("a/a1.go")
|
|
env.Await(
|
|
// The editor should pop up a message suggesting that the user
|
|
// run `go mod vendor`, along with a button to do so.
|
|
// By default, the fake editor always accepts such suggestions,
|
|
// so once we see the request, we can assume that `go mod vendor`
|
|
// will be executed.
|
|
OnceMet(
|
|
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidOpen), 1),
|
|
ShowMessageRequest("go mod vendor"),
|
|
),
|
|
)
|
|
env.CheckForFileChanges()
|
|
env.Await(
|
|
OnceMet(
|
|
CompletedWork(lsp.DiagnosticWorkTitle(lsp.FromDidChangeWatchedFiles), 1),
|
|
DiagnosticAt("a/a1.go", 6, 5),
|
|
),
|
|
)
|
|
}, WithProxy(basicProxy))
|
|
}
|