Skip to content

Commit b7525f4

Browse files
committed
internal/lsp: hash go version into package key
The go directive affects type checking errors so it should be included in the package key. I manually tested that this fixes the issue in golang/go#51325 Fixes golang/go#51325 Change-Id: I109859ae65e7e4d5fdefc63a0a7a838117ee02cf Reviewed-on: https://go-review.googlesource.com/c/tools/+/387914 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 5210e0c commit b7525f4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

internal/lsp/cache/check.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (s *snapshot) buildKey(ctx context.Context, id PackageID, mode source.Parse
194194
depKeys = append(depKeys, depHandle.key)
195195
}
196196
experimentalKey := s.View().Options().ExperimentalPackageCacheKey
197-
ph.key = checkPackageKey(ph.m.ID, compiledGoFiles, m.Config, depKeys, mode, experimentalKey)
197+
ph.key = checkPackageKey(ph.m.ID, compiledGoFiles, m, depKeys, mode, experimentalKey)
198198
return ph, deps, nil
199199
}
200200

@@ -214,15 +214,18 @@ func (s *snapshot) workspaceParseMode(id PackageID) source.ParseMode {
214214
return source.ParseExported
215215
}
216216

217-
func checkPackageKey(id PackageID, pghs []*parseGoHandle, cfg *packages.Config, deps []packageHandleKey, mode source.ParseMode, experimentalKey bool) packageHandleKey {
217+
func checkPackageKey(id PackageID, pghs []*parseGoHandle, m *KnownMetadata, deps []packageHandleKey, mode source.ParseMode, experimentalKey bool) packageHandleKey {
218218
b := bytes.NewBuffer(nil)
219219
b.WriteString(string(id))
220+
if m.Module != nil {
221+
b.WriteString(m.Module.GoVersion) // go version affects type check errors.
222+
}
220223
if !experimentalKey {
221224
// cfg was used to produce the other hashed inputs (package ID, parsed Go
222225
// files, and deps). It should not otherwise affect the inputs to the type
223226
// checker, so this experiment omits it. This should increase cache hits on
224227
// the daemon as cfg contains the environment and working directory.
225-
b.WriteString(hashConfig(cfg))
228+
b.WriteString(hashConfig(m.Config))
226229
}
227230
b.WriteByte(byte(mode))
228231
for _, dep := range deps {

0 commit comments

Comments
 (0)