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>
This commit is contained in:
Heschi Kreinick 2020-10-30 16:50:36 -04:00
parent aefe0b7421
commit 22bd85271a
4 changed files with 2 additions and 81 deletions

View File

@ -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 --

View File

@ -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) {

View File

@ -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 {

View File

@ -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,
},