Skip to content

Commit c143b86

Browse files
committed
Workaround versioned document edits sent by gopls
This fixes Organize Imports code action for gopls version >= 0.3.1. Fixes #31
1 parent 91db24d commit c143b86

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/lsp/acmelsp/acmelsp.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,20 @@ func CodeActionAndFormat(ctx context.Context, server FormatServer, doc *protocol
199199
}
200200

201201
func editWorkspace(we *protocol.WorkspaceEdit) error {
202-
if we == nil || we.Changes == nil {
202+
if we == nil {
203+
return nil // no changes to apply
204+
}
205+
if we.Changes == nil && we.DocumentChanges != nil {
206+
// gopls version >= 0.3.1 sends versioned document edits
207+
// for organizeImports code action even when we don't
208+
// support it. Convert versioned edits to non-versioned.
209+
changes := make(map[string][]protocol.TextEdit)
210+
for _, dc := range we.DocumentChanges {
211+
changes[dc.TextDocument.TextDocumentIdentifier.URI] = dc.Edits
212+
}
213+
we.Changes = &changes
214+
}
215+
if we.Changes == nil {
203216
return nil // no changes to apply
204217
}
205218

0 commit comments

Comments
 (0)