diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go index d3685ddac1..83decca0f5 100644 --- a/gopls/internal/regtest/diagnostics_test.go +++ b/gopls/internal/regtest/diagnostics_test.go @@ -639,6 +639,7 @@ var ErrHelpWanted error // Test for golang/go#38211. func Test_Issue38211(t *testing.T) { + t.Skip("Requires CL 267577 to work without the save hook.") testenv.NeedsGo1Point(t, 14) const ardanLabs = ` -- go.mod -- diff --git a/gopls/internal/regtest/modfile_test.go b/gopls/internal/regtest/modfile_test.go index b1bc508919..69ff5e9441 100644 --- a/gopls/internal/regtest/modfile_test.go +++ b/gopls/internal/regtest/modfile_test.go @@ -462,44 +462,6 @@ func main() { }) } -func TestTidyOnSave(t *testing.T) { - testenv.NeedsGo1Point(t, 14) - - const untidyModule = ` --- go.mod -- -module mod.com - -go 1.14 - -require random.org v1.2.3 --- main.go -- -package main - -import "example.com/blah" - -func main() { - fmt.Println(blah.Name) -} -` - withOptions(WithProxyFiles(proxy)).run(t, untidyModule, func(t *testing.T, env *Env) { - env.OpenFile("go.mod") - env.Await( - env.DiagnosticAtRegexp("main.go", `"example.com/blah"`), - env.DiagnosticAtRegexp("go.mod", `require random.org v1.2.3`), - ) - env.SaveBuffer("go.mod") - const want = `module mod.com - -go 1.14 - -require example.com v1.2.3 -` - if got := env.ReadWorkspaceFile("go.mod"); got != want { - t.Fatalf("unexpected go.mod content:\n%s", tests.Diff(want, got)) - } - }) -} - // Confirm that an error in an indirect dependency of a requirement is surfaced // as a diagnostic in the go.mod file. func TestErrorInIndirectDependency(t *testing.T) { diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index af7eeb3d10..b3a3ce3d20 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go @@ -70,16 +70,6 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara } codeActions = append(codeActions, modQuickFixes...) } - if wanted[protocol.SourceOrganizeImports] { - action, err := goModTidy(ctx, snapshot, fh) - if source.IsNonFatalGoModError(err) { - return nil, nil - } - if err != nil { - return nil, err - } - codeActions = append(codeActions, *action) - } case source.Go: // Don't suggest fixes for generated files, since they are generally // not useful and some editors may apply them automatically on save. @@ -542,38 +532,6 @@ func sameDiagnostic(d protocol.Diagnostic, e source.Error) bool { return d.Message == e.Message && protocol.CompareRange(d.Range, e.Range) == 0 && d.Source == e.Category } -func goModTidy(ctx context.Context, snapshot source.Snapshot, fh source.VersionedFileHandle) (*protocol.CodeAction, error) { - tidied, err := snapshot.ModTidy(ctx, fh) - if err != nil { - return nil, err - } - left, err := fh.Read() - if err != nil { - return nil, err - } - right := tidied.TidiedContent - edits := snapshot.View().Options().ComputeEdits(fh.URI(), string(left), string(right)) - protocolEdits, err := source.ToProtocolEdits(tidied.Parsed.Mapper, edits) - if err != nil { - return nil, err - } - return &protocol.CodeAction{ - Title: "Tidy", - Kind: protocol.SourceOrganizeImports, - Edit: protocol.WorkspaceEdit{ - DocumentChanges: []protocol.TextDocumentEdit{{ - TextDocument: protocol.VersionedTextDocumentIdentifier{ - Version: fh.Version(), - TextDocumentIdentifier: protocol.TextDocumentIdentifier{ - URI: protocol.URIFromSpanURI(fh.URI()), - }, - }, - Edits: protocolEdits, - }}, - }, - }, err -} - func goTest(ctx context.Context, snapshot source.Snapshot, uri span.URI, rng protocol.Range) ([]protocol.CodeAction, error) { fh, err := snapshot.GetFile(ctx, uri) if err != nil { diff --git a/internal/lsp/mod/code_lens.go b/internal/lsp/mod/code_lens.go index dc2e4144a6..db2aea2e3c 100644 --- a/internal/lsp/mod/code_lens.go +++ b/internal/lsp/mod/code_lens.go @@ -116,7 +116,7 @@ func tidyLens(ctx context.Context, snapshot source.Snapshot, fh source.FileHandl return []protocol.CodeLens{{ Range: rng, Command: protocol.Command{ - Title: "Tidy module", + Title: source.CommandTidy.Title, Command: source.CommandTidy.ID(), Arguments: goModArgs, },