diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index a830cc7f59..366a7afe13 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -249,15 +249,6 @@ func computePackageKey(id PackageID, files []source.FileHandle, m *KnownMetadata return packageHandleKey(source.HashOf(b.Bytes())) } -// hashEnv returns a hash of the snapshot's configuration. -func hashEnv(s *snapshot) source.Hash { - s.view.optionsMu.Lock() - env := s.view.options.EnvSlice() - s.view.optionsMu.Unlock() - - return source.Hashf("%s", env) -} - // hashConfig returns the hash for the *packages.Config. func hashConfig(config *packages.Config) source.Hash { // TODO(adonovan): opt: don't materialize the bytes; hash them directly. diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go index 8e6017648c..f9d148b737 100644 --- a/internal/lsp/cache/mod.go +++ b/internal/lsp/cache/mod.go @@ -223,33 +223,14 @@ func (s *snapshot) ModWhy(ctx context.Context, fh source.FileHandle) (map[string // cache miss? if !hit { - // TODO(adonovan): use a simpler cache of promises that - // is shared across snapshots. See comment at modTidyKey. - // We can then delete hashEnv too. - type modWhyKey struct { - // TODO(rfindley): is sessionID used to identify overlays because modWhy - // looks at overlay state? In that case, I am not sure that this key - // is actually correct. The key should probably just be URI, and - // invalidated in clone when any import changes. - sessionID string - env source.Hash - view string - mod source.FileIdentity - } - key := modWhyKey{ - sessionID: s.view.session.id, - env: hashEnv(s), - mod: fh.FileIdentity(), - view: s.view.rootURI.Filename(), - } - handle, release := s.store.Handle(key, func(ctx context.Context, arg interface{}) interface{} { + handle := memoize.NewHandle("modWhy", func(ctx context.Context, arg interface{}) interface{} { why, err := modWhyImpl(ctx, arg.(*snapshot), fh) return modWhyResult{why, err} }) entry = handle s.mu.Lock() - s.modWhyHandles.Set(uri, entry, func(_, _ interface{}) { release() }) + s.modWhyHandles.Set(uri, entry, nil) s.mu.Unlock() }