From c143b86e62204682c98e5e3cd8c7e2cea8ab234e Mon Sep 17 00:00:00 2001 From: Fazlul Shahriar Date: Sun, 16 Feb 2020 11:36:50 -0500 Subject: [PATCH] Workaround versioned document edits sent by gopls This fixes Organize Imports code action for gopls version >= 0.3.1. Fixes #31 --- internal/lsp/acmelsp/acmelsp.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/lsp/acmelsp/acmelsp.go b/internal/lsp/acmelsp/acmelsp.go index 67dc6db..3071026 100644 --- a/internal/lsp/acmelsp/acmelsp.go +++ b/internal/lsp/acmelsp/acmelsp.go @@ -199,7 +199,20 @@ func CodeActionAndFormat(ctx context.Context, server FormatServer, doc *protocol } func editWorkspace(we *protocol.WorkspaceEdit) error { - if we == nil || we.Changes == nil { + if we == nil { + return nil // no changes to apply + } + if we.Changes == nil && we.DocumentChanges != nil { + // gopls version >= 0.3.1 sends versioned document edits + // for organizeImports code action even when we don't + // support it. Convert versioned edits to non-versioned. + changes := make(map[string][]protocol.TextEdit) + for _, dc := range we.DocumentChanges { + changes[dc.TextDocument.TextDocumentIdentifier.URI] = dc.Edits + } + we.Changes = &changes + } + if we.Changes == nil { return nil // no changes to apply }