Skip to content

Commit

Permalink
Workaround versioned document edits sent by gopls
Browse files Browse the repository at this point in the history
This fixes Organize Imports code action for gopls version >= 0.3.1.

Fixes #31
  • Loading branch information
fhs committed Feb 16, 2020
1 parent 91db24d commit c143b86
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/lsp/acmelsp/acmelsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c143b86

Please sign in to comment.