diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index c8dc650b57..dffecb1424 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -616,14 +616,7 @@ func (s *snapshot) reloadOrphanedFiles(ctx context.Context) error { s.mu.Unlock() } for _, m := range m { - // If a package's files belong to this view, it is a workspace package - // and should be added to the set of workspace packages. - for _, uri := range m.compiledGoFiles { - if !contains(s.view.session.viewsOf(uri), s.view) { - continue - } - s.setWorkspacePackage(ctx, m) - } + s.setWorkspacePackage(ctx, m) } return nil } @@ -638,6 +631,11 @@ func (s *snapshot) orphanedFileScopes() []interface{} { if fh.Identity().Kind != source.Go { continue } + // If the URI doesn't belong to this view, then it's not in a workspace + // package and should not be reloaded directly. + if !contains(s.view.session.viewsOf(uri), s.view) { + continue + } // Don't reload metadata for files we've already deemed unloadable. if _, ok := s.unloadableFiles[uri]; ok { continue