mirror of https://github.com/golang/go.git
internal/lsp/cache: copy workFile when invalidating workspace
to avoid losing workFile information when that happens. This fixes an issue where diagnostics, hover, etc didn't show up after the initial load when some changes were made to go.work files. Change-Id: I42e2dcfd94a5b4726856ab0a4d8dfc9c1efc48b1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/391257 Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
e7a12a333d
commit
622cf7b338
|
|
@ -802,13 +802,28 @@ func TestUseGoWorkDiagnosticMissingModule(t *testing.T) {
|
|||
go 1.18
|
||||
|
||||
use ./foo
|
||||
-- bar/go.mod --
|
||||
module example.com/bar
|
||||
`
|
||||
Run(t, files, func(t *testing.T, env *Env) {
|
||||
env.OpenFile("go.work")
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexpWithMessage("go.work", "use", "directory ./foo does not contain a module"),
|
||||
)
|
||||
t.Log("bar")
|
||||
// The following tests is a regression test against an issue where we weren't
|
||||
// copying the workFile struct field on workspace when a new one was created in
|
||||
// (*workspace).invalidate. Set the buffer content to a working file so that
|
||||
// invalidate recognizes the workspace to be change and copies over the workspace
|
||||
// struct, and then set the content back to the old contents to make sure
|
||||
// the diagnostic still shows up.
|
||||
env.SetBufferContent("go.work", "go 1.18 \n\n use ./bar\n")
|
||||
env.Await(
|
||||
env.NoDiagnosticAtRegexp("go.work", "use"),
|
||||
)
|
||||
env.SetBufferContent("go.work", "go 1.18 \n\n use ./foo\n")
|
||||
env.Await(
|
||||
env.DiagnosticAtRegexpWithMessage("go.work", "use", "directory ./foo does not contain a module"),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ func (w *workspace) invalidate(ctx context.Context, changes map[span.URI]*fileCh
|
|||
moduleSource: w.moduleSource,
|
||||
knownModFiles: make(map[span.URI]struct{}),
|
||||
activeModFiles: make(map[span.URI]struct{}),
|
||||
workFile: w.workFile,
|
||||
mod: w.mod,
|
||||
sum: w.sum,
|
||||
wsDirs: w.wsDirs,
|
||||
|
|
|
|||
Loading…
Reference in New Issue