LSP: Make applyEdit return a response (#12270)

According to the specification workspace/applyEdit needs to respond with
a `ApplyWorkspaceEditResponse`

See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit

This is a subset of https://github.com/neovim/neovim/pull/11607
This commit is contained in:
Mathias Fußenegger 2020-05-11 16:56:35 +02:00 committed by GitHub
parent 9816173fb3
commit 55b62a937c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -17,7 +17,11 @@ M['workspace/applyEdit'] = function(_, _, workspace_edit)
if workspace_edit.label then if workspace_edit.label then
print("Workspace edit", workspace_edit.label) print("Workspace edit", workspace_edit.label)
end end
util.apply_workspace_edit(workspace_edit.edit) local status, result = pcall(util.apply_workspace_edit, workspace_edit.edit)
return {
applied = status;
failureReason = result;
}
end end
M['textDocument/publishDiagnostics'] = function(_, _, result) M['textDocument/publishDiagnostics'] = function(_, _, result)

View File

@ -913,7 +913,21 @@ describe('LSP', function()
}, buf_lines(target_bufnr)) }, buf_lines(target_bufnr))
end) end)
end) end)
describe('workspace_apply_edit', function()
it('workspace/applyEdit returns ApplyWorkspaceEditResponse', function()
local expected = {
applied = true;
failureReason = nil;
}
eq(expected, exec_lua [[
local apply_edit = {
label = nil;
edit = {};
}
return vim.lsp.callbacks['workspace/applyEdit'](nil, nil, apply_edit)
]])
end)
end)
describe('completion_list_to_complete_items', function() describe('completion_list_to_complete_items', function()
-- Completion option precedence: -- Completion option precedence:
-- textEdit.newText > insertText > label -- textEdit.newText > insertText > label