Skip to content

Commit 0f3433c

Browse files
committed
[gopls-release-branch.0.9] internal/lsp/progress: actually close over
Context in WorkDoneWriter In addition to the original commit description reproduced below, this CL updates gopls/go.mod to include a replace directive for x/tools. CL 409936 eliminated cases where we close over a Context during progress reporting, except in one instance where it wasn't possible: the WorkDoneWriter that must implement the io.Writer interface. Unfortunately it contained a glaring bug that the ctx field was never set, and the regression test for progress reporting during `go generate` was disabled due to flakiness (golang/go#49901). Incidentally, the fundamental problem that CL 409936 addressed may also fix the flakiness of TestGenerateProgress. Fix the bug, and re-enable the test. For golang/go#53781 For golang/go#53823 Change-Id: Ideb99a5525667e45d2e41fcc5078699ba1e0f1a3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/417115 gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Robert Findley <[email protected]> Auto-Submit: Robert Findley <[email protected]> Reviewed-by: Alan Donovan <[email protected]> (cherry picked from commit 459e2b8) Reviewed-on: https://go-review.googlesource.com/c/tools/+/417118 Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 6131980 commit 0f3433c

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

gopls/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ require (
2424
golang.org/x/text v0.3.7 // indirect
2525
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
2626
)
27+
28+
replace golang.org/x/tools => ../

gopls/internal/regtest/misc/generate_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
)
1717

1818
func TestGenerateProgress(t *testing.T) {
19-
t.Skipf("skipping flaky test: https://golang.org/issue/49901")
20-
2119
const generatedWorkspace = `
2220
-- go.mod --
2321
module fake.test

internal/lsp/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (c *commandHandler) runTests(ctx context.Context, snapshot source.Snapshot,
404404
// create output
405405
buf := &bytes.Buffer{}
406406
ew := progress.NewEventWriter(ctx, "test")
407-
out := io.MultiWriter(ew, progress.NewWorkDoneWriter(work), buf)
407+
out := io.MultiWriter(ew, progress.NewWorkDoneWriter(ctx, work), buf)
408408

409409
// Run `go test -run Func` on each test.
410410
var failedTests int
@@ -487,7 +487,7 @@ func (c *commandHandler) Generate(ctx context.Context, args command.GenerateArgs
487487
Args: []string{"-x", pattern},
488488
WorkingDir: args.Dir.SpanURI().Filename(),
489489
}
490-
stderr := io.MultiWriter(er, progress.NewWorkDoneWriter(deps.work))
490+
stderr := io.MultiWriter(er, progress.NewWorkDoneWriter(ctx, deps.work))
491491
if err := deps.snapshot.RunGoCommandPiped(ctx, source.Normal, inv, er, stderr); err != nil {
492492
return err
493493
}

internal/lsp/progress/progress.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ type WorkDoneWriter struct {
260260
wd *WorkDone
261261
}
262262

263-
func NewWorkDoneWriter(wd *WorkDone) *WorkDoneWriter {
264-
return &WorkDoneWriter{wd: wd}
263+
func NewWorkDoneWriter(ctx context.Context, wd *WorkDone) *WorkDoneWriter {
264+
return &WorkDoneWriter{ctx: ctx, wd: wd}
265265
}
266266

267267
func (wdw *WorkDoneWriter) Write(p []byte) (n int, err error) {

0 commit comments

Comments
 (0)