chore: adapt lsp request handler for nvim >= 0.5.1

https://github.com/neovim/neovim/pull/15504
This commit is contained in:
Omar Zeghouani
2021-09-07 11:55:46 +01:00
parent 02ce2dab13
commit 962ad42512
5 changed files with 36 additions and 7 deletions

View File

@@ -2,6 +2,31 @@ local vim = vim
local M = {}
-- callback args changed in Neovim 0.5.1/0.6. See:
-- https://github.com/neovim/neovim/pull/15504
local function mk_handler(fn)
return function(...)
local config_or_client_id = select(4, ...)
local is_new = type(config_or_client_id) ~= "number"
if is_new then
fn(...)
else
local err = select(1, ...)
local method = select(2, ...)
local result = select(3, ...)
local client_id = select(4, ...)
local bufnr = select(5, ...)
local config = select(6, ...)
fn(err, result, { method = method, client_id = client_id, bufnr = bufnr }, config)
end
end
end
-- from mfussenegger/nvim-lsp-compl@29a81f3
function M.request(bufnr, method, params, handler)
return vim.lsp.buf_request(bufnr, method, params, mk_handler(handler))
end
function M.is_buf_attached_to_lsp(bufnr)
local clients = vim.lsp.buf_get_clients(bufnr or 0)
return clients ~= nil and #clients > 0