Skip to content

Commit fd9fd22

Browse files
committed
internal/lsp: correctly apply file edits for edit go directive
Fixes a bug where the go mod edit -go=version file edits are never actually applied. Change-Id: Id055b0fad3399a00e1245556eb39073f15be09d9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/389216 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 4a5e7f0) Reviewed-on: https://go-review.googlesource.com/c/tools/+/389494 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]>
1 parent f86e71d commit fd9fd22

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

internal/lsp/command.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,18 @@ func (c *commandHandler) EditGoDirective(ctx context.Context, args command.EditG
266266
requireSave: true, // if go.mod isn't saved it could cause a problem
267267
forURI: args.URI,
268268
}, func(ctx context.Context, deps commandDeps) error {
269-
_, err := deps.snapshot.RunGoCommandDirect(ctx, source.Normal, &gocommand.Invocation{
270-
Verb: "mod",
271-
Args: []string{"edit", "-go", args.Version},
272-
WorkingDir: filepath.Dir(args.URI.SpanURI().Filename()),
273-
})
274-
return err
269+
snapshot, fh, ok, release, err := c.s.beginFileRequest(ctx, args.URI, source.UnknownKind)
270+
defer release()
271+
if !ok {
272+
return err
273+
}
274+
if err := c.s.runGoModUpdateCommands(ctx, snapshot, fh.URI(), func(invoke func(...string) (*bytes.Buffer, error)) error {
275+
_, err := invoke("mod", "edit", "-go", args.Version)
276+
return err
277+
}); err != nil {
278+
return err
279+
}
280+
return nil
275281
})
276282
}
277283

0 commit comments

Comments
 (0)