Skip to content

Commit 22bd852

Browse files
committed
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>
1 parent aefe0b7 commit 22bd852

File tree

4 files changed

+2
-81
lines changed

4 files changed

+2
-81
lines changed

gopls/internal/regtest/diagnostics_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ var ErrHelpWanted error
639639

640640
// Test for golang/go#38211.
641641
func Test_Issue38211(t *testing.T) {
642+
t.Skip("Requires CL 267577 to work without the save hook.")
642643
testenv.NeedsGo1Point(t, 14)
643644
const ardanLabs = `
644645
-- go.mod --

gopls/internal/regtest/modfile_test.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -462,44 +462,6 @@ func main() {
462462
})
463463
}
464464

465-
func TestTidyOnSave(t *testing.T) {
466-
testenv.NeedsGo1Point(t, 14)
467-
468-
const untidyModule = `
469-
-- go.mod --
470-
module mod.com
471-
472-
go 1.14
473-
474-
require random.org v1.2.3
475-
-- main.go --
476-
package main
477-
478-
import "example.com/blah"
479-
480-
func main() {
481-
fmt.Println(blah.Name)
482-
}
483-
`
484-
withOptions(WithProxyFiles(proxy)).run(t, untidyModule, func(t *testing.T, env *Env) {
485-
env.OpenFile("go.mod")
486-
env.Await(
487-
env.DiagnosticAtRegexp("main.go", `"example.com/blah"`),
488-
env.DiagnosticAtRegexp("go.mod", `require random.org v1.2.3`),
489-
)
490-
env.SaveBuffer("go.mod")
491-
const want = `module mod.com
492-
493-
go 1.14
494-
495-
require example.com v1.2.3
496-
`
497-
if got := env.ReadWorkspaceFile("go.mod"); got != want {
498-
t.Fatalf("unexpected go.mod content:\n%s", tests.Diff(want, got))
499-
}
500-
})
501-
}
502-
503465
// Confirm that an error in an indirect dependency of a requirement is surfaced
504466
// as a diagnostic in the go.mod file.
505467
func TestErrorInIndirectDependency(t *testing.T) {

internal/lsp/code_action.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara
7070
}
7171
codeActions = append(codeActions, modQuickFixes...)
7272
}
73-
if wanted[protocol.SourceOrganizeImports] {
74-
action, err := goModTidy(ctx, snapshot, fh)
75-
if source.IsNonFatalGoModError(err) {
76-
return nil, nil
77-
}
78-
if err != nil {
79-
return nil, err
80-
}
81-
codeActions = append(codeActions, *action)
82-
}
8373
case source.Go:
8474
// Don't suggest fixes for generated files, since they are generally
8575
// not useful and some editors may apply them automatically on save.
@@ -542,38 +532,6 @@ func sameDiagnostic(d protocol.Diagnostic, e source.Error) bool {
542532
return d.Message == e.Message && protocol.CompareRange(d.Range, e.Range) == 0 && d.Source == e.Category
543533
}
544534

545-
func goModTidy(ctx context.Context, snapshot source.Snapshot, fh source.VersionedFileHandle) (*protocol.CodeAction, error) {
546-
tidied, err := snapshot.ModTidy(ctx, fh)
547-
if err != nil {
548-
return nil, err
549-
}
550-
left, err := fh.Read()
551-
if err != nil {
552-
return nil, err
553-
}
554-
right := tidied.TidiedContent
555-
edits := snapshot.View().Options().ComputeEdits(fh.URI(), string(left), string(right))
556-
protocolEdits, err := source.ToProtocolEdits(tidied.Parsed.Mapper, edits)
557-
if err != nil {
558-
return nil, err
559-
}
560-
return &protocol.CodeAction{
561-
Title: "Tidy",
562-
Kind: protocol.SourceOrganizeImports,
563-
Edit: protocol.WorkspaceEdit{
564-
DocumentChanges: []protocol.TextDocumentEdit{{
565-
TextDocument: protocol.VersionedTextDocumentIdentifier{
566-
Version: fh.Version(),
567-
TextDocumentIdentifier: protocol.TextDocumentIdentifier{
568-
URI: protocol.URIFromSpanURI(fh.URI()),
569-
},
570-
},
571-
Edits: protocolEdits,
572-
}},
573-
},
574-
}, err
575-
}
576-
577535
func goTest(ctx context.Context, snapshot source.Snapshot, uri span.URI, rng protocol.Range) ([]protocol.CodeAction, error) {
578536
fh, err := snapshot.GetFile(ctx, uri)
579537
if err != nil {

internal/lsp/mod/code_lens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func tidyLens(ctx context.Context, snapshot source.Snapshot, fh source.FileHandl
116116
return []protocol.CodeLens{{
117117
Range: rng,
118118
Command: protocol.Command{
119-
Title: "Tidy module",
119+
Title: source.CommandTidy.Title,
120120
Command: source.CommandTidy.ID(),
121121
Arguments: goModArgs,
122122
},

0 commit comments

Comments
 (0)