From bd27a71ec294b5d388bc2c233d397a76c3f21cf2 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 29 Aug 2023 18:40:50 +0200 Subject: try to convert workspaceEdit.documentChanges to plain changes We do not support workspaceEdit.documentChanges but some LSP servers do not respect our capabilities and send them anyways. Try to optimistically convert simple documentChanges to plain changes. We only support simple TextDocumentEdit[]. --- init.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 33cb547..7d82bcb 100644 --- a/init.lua +++ b/init.lua @@ -499,7 +499,18 @@ end -- apply a WorkspaceEdit received from the language server local function vis_apply_workspaceEdit(_, _, workspaceEdit) local file_edits = workspaceEdit.changes - assert(file_edits) + assert(file_edits or workspaceEdit.documentChanges) + + -- try to convert NOT SUPPORTED TextDocumentEdit[] + -- We do not announce suppport for versioned DocumentChanges in our + -- client capabilities, but some LSP servers ignore our capabilities + -- sending them anyway. + if not file_edits then + file_edits = {} + for _, edit in ipairs(workspaceEdit.documentChanges) do + file_edits[edit.textDocument.uri] = edit.edits + end + end -- generate change summary local summary = '--- workspace edit summary ---\n' -- cgit v1.2.3