internal/lsp: remove organize imports action for go.mod

Per our discussion, it's too slow for a save hook.

Fixes golang/go#38209. (for real this time?)

Change-Id: I264c6d1590a374eff09b09cb1a9162e8e5ff2dc7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267682
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go
index d3685dd..83decca 100644
--- a/gopls/internal/regtest/diagnostics_test.go
+++ b/gopls/internal/regtest/diagnostics_test.go
@@ -639,6 +639,7 @@
 
 // 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 b1bc508..69ff5e9 100644
--- a/gopls/internal/regtest/modfile_test.go
+++ b/gopls/internal/regtest/modfile_test.go
@@ -462,44 +462,6 @@
 	})
 }
 
-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 af7eeb3..b3a3ce3 100644
--- a/internal/lsp/code_action.go
+++ b/internal/lsp/code_action.go
@@ -70,16 +70,6 @@
 			}
 			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 @@
 	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 dc2e414..db2aea2 100644
--- a/internal/lsp/mod/code_lens.go
+++ b/internal/lsp/mod/code_lens.go
@@ -116,7 +116,7 @@
 	return []protocol.CodeLens{{
 		Range: rng,
 		Command: protocol.Command{
-			Title:     "Tidy module",
+			Title:     source.CommandTidy.Title,
 			Command:   source.CommandTidy.ID(),
 			Arguments: goModArgs,
 		},