diff --git a/internal/lsp/cache/gofile.go b/internal/lsp/cache/gofile.go index c22ae6bcbfc..e368fa36399 100644 --- a/internal/lsp/cache/gofile.go +++ b/internal/lsp/cache/gofile.go @@ -26,11 +26,6 @@ type goFile struct { // It contains any packages with `go list` errors. missingImports map[packagePath]struct{} - // justOpened indicates that the file has just been opened. - // We re-run go/packages.Load on just opened files to make sure - // that we know about all of their packages. - justOpened bool - imports []*ast.ImportSpec cphs map[packageKey]*checkPackageHandle @@ -138,16 +133,6 @@ func (f *goFile) isDirty(ctx context.Context, fh source.FileHandle) bool { f.mu.Lock() defer f.mu.Unlock() - // If the the file has just been opened, - // it may be part of more packages than we are aware of. - // - // Note: This must be the first case, otherwise we may not reset the value of f.justOpened. - if f.justOpened { - f.meta = make(map[packageID]*metadata) - f.cphs = make(map[packageKey]*checkPackageHandle) - f.justOpened = false - return true - } if len(f.meta) == 0 || len(f.cphs) == 0 { return true } diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 81ecafec3bd..34d89d54723 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -229,9 +229,10 @@ func (s *session) DidOpen(ctx context.Context, uri span.URI, kind source.FileKin log.Error(ctx, "not a Go file", nil, telemetry.File) return } - // Mark file as open. + // Force a reload of the package metadata by clearing the cached data. gof.mu.Lock() - gof.justOpened = true + gof.meta = make(map[packageID]*metadata) + gof.cphs = make(map[packageKey]*checkPackageHandle) gof.mu.Unlock() } } diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index 5033004be24..ba56315fce3 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -69,7 +69,6 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) { for filename, content := range data.Config.Overlay { session.SetOverlay(span.FileURI(filename), source.DetectLanguage("", filename), content) } - r := &runner{ server: &Server{ session: session,