Skip to content

Commit 5974258

Browse files
committed
gopls/internal/lsp: clear vuln diagnostics on config changes
Clear vuln diagnostics before diagnosing views, during handling of config changes. This should mostly avoid the symptoms of golang/go#60465, but as noted in the code is not a proper fix. Unfortunately there is no way to write a test for this behavior that is not flaky, because the operation itself is flaky. I have scheduled a proper fix for [email protected]. Fixes golang/go#60465 Change-Id: If41f5420c24dfa15a7d83e89988488619a2dd857 Reviewed-on: https://go-review.googlesource.com/c/tools/+/498560 gopls-CI: kokoro <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent f3faea1 commit 5974258

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

gopls/internal/lsp/cache/snapshot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,10 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
21562156
if !change.exists {
21572157
result.files.Delete(uri)
21582158
} else {
2159+
// TODO(golang/go#57558): the line below is strictly necessary to ensure
2160+
// that snapshots have each overlay, but it is problematic that we must
2161+
// set any content in snapshot.clone: if the file has changed, let it be
2162+
// re-read.
21592163
result.files.Set(uri, change.fileHandle)
21602164
}
21612165

gopls/internal/lsp/workspace.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,30 @@ func (s *Server) didChangeConfiguration(ctx context.Context, _ *protocol.DidChan
6161
if err := s.fetchConfig(ctx, view.Name(), view.Folder(), options); err != nil {
6262
return err
6363
}
64-
view, err := s.session.SetViewOptions(ctx, view, options)
64+
_, err := s.session.SetViewOptions(ctx, view, options)
6565
if err != nil {
6666
return err
6767
}
68+
}
69+
70+
// Now that all views have been updated: reset vulncheck diagnostics, rerun
71+
// diagnostics, and hope for the best...
72+
//
73+
// TODO(golang/go#60465): this not a reliable way to ensure the correctness
74+
// of the resulting diagnostics below. A snapshot could still be in the
75+
// process of diagnosing the workspace, and not observe the configuration
76+
// changes above.
77+
//
78+
// The real fix is golang/go#42814: we should create a new snapshot on any
79+
// change that could affect the derived results in that snapshot. However, we
80+
// are currently (2023-05-26) on the verge of a release, and the proper fix
81+
// is too risky a change. Since in the common case a configuration change is
82+
// only likely to occur during a period of quiescence on the server, it is
83+
// likely that the clearing below will have the desired effect.
84+
s.clearDiagnosticSource(modVulncheckSource)
85+
86+
for _, view := range s.session.Views() {
87+
view := view
6888
go func() {
6989
snapshot, release, err := view.Snapshot()
7090
if err != nil {

0 commit comments

Comments
 (0)