Skip to content

Commit dd89a2e

Browse files
committed
gopls/internal/lsp: remove now redundant debouncing logic
Now that we cancel the debouncing operation on cancellation of the background context, debouncing is actually unnecessary. The cancellation of earlier background contexts occurs whenever a new snapshot is created for the view, has the same effect as debouncing (but better, because cancellation occurs immediately and not when we reach the call to debounce). Also, simplify the control flow of diagnoseSnapshot. Change-Id: I04e076d759e8a0a15238a219eb683c0d9a239677 Reviewed-on: https://go-review.googlesource.com/c/tools/+/487138 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 2a9398d commit dd89a2e

File tree

5 files changed

+6
-190
lines changed

5 files changed

+6
-190
lines changed

gopls/internal/lsp/debounce.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

gopls/internal/lsp/debounce_test.go

Lines changed: 0 additions & 97 deletions
This file was deleted.

gopls/internal/lsp/diagnostics.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,17 @@ func (s *Server) diagnoseSnapshot(snapshot source.Snapshot, changedURIs []span.U
181181
// does not analyze) packages directly affected by
182182
// file modifications.
183183
//
184-
// The second phase runs analysis on the entire snapshot,
185-
// and is debounced by the configured delay.
184+
// The second phase runs after the delay, and does everything.
186185
s.diagnoseChangedFiles(ctx, snapshot, changedURIs, onDisk)
187186
s.publishDiagnostics(ctx, false, snapshot)
188187

189-
// We debounce diagnostics separately for each view, using the snapshot
190-
// local ID as logical ordering.
191-
//
192-
// TODO(rfindley): it would be cleaner to simply put the diagnostic
193-
// debouncer on the view, and remove the "key" argument to debouncing.
194-
if ok := <-s.diagDebouncer.debounce(ctx, snapshot.View().ID(), uint64(snapshot.GlobalID()), time.After(delay)); ok {
195-
s.diagnose(ctx, snapshot, analyzeOpenPackages)
196-
s.publishDiagnostics(ctx, true, snapshot)
188+
select {
189+
case <-time.After(delay):
190+
case <-ctx.Done():
191+
return
197192
}
198-
return
199193
}
200194

201-
// Ignore possible workspace configuration warnings in the normal flow.
202195
s.diagnose(ctx, snapshot, analyzeOpenPackages)
203196
s.publishDiagnostics(ctx, true, snapshot)
204197
}

gopls/internal/lsp/server.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func NewServer(session *cache.Session, client protocol.ClientCloser) *Server {
3535
client: client,
3636
diagnosticsSema: make(chan struct{}, concurrentAnalyses),
3737
progress: progress.NewTracker(client),
38-
diagDebouncer: newDebouncer(),
3938
}
4039
}
4140

@@ -105,9 +104,6 @@ type Server struct {
105104

106105
progress *progress.Tracker
107106

108-
// diagDebouncer is used for debouncing diagnostics.
109-
diagDebouncer *debouncer
110-
111107
// When the workspace fails to load, we show its status through a progress
112108
// report with an error message.
113109
criticalErrorStatusMu sync.Mutex

gopls/internal/regtest/workspace/workspace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ use (
647647
}
648648

649649
// This fails if guarded with a OnceMet(DoneWithSave(), ...), because it is
650-
// debounced (and therefore not synchronous with the change).
650+
// delayed (and therefore not synchronous with the change).
651651
env.Await(NoDiagnostics(ForFile("modb/go.mod")))
652652

653653
// Test Formatting.

0 commit comments

Comments
 (0)