feature: make peek function work in neovim head and 0.5 (#1559)

This commit is contained in:
Abouzar Parvan 2021-09-15 23:42:57 +04:30 committed by GitHub
parent df0da6fc75
commit 168eb232d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -54,9 +54,8 @@ local function create_floating_file(location, opts)
return bufnr, winnr
end
local function preview_location_callback(_, method, result)
local function preview_location_callback(result)
if result == nil or vim.tbl_isempty(result) then
print("peek: No location found: " .. method)
return nil
end
@ -74,6 +73,14 @@ local function preview_location_callback(_, method, result)
end
end
local function preview_location_callback_old_signature(_, _, result)
return preview_location_callback(result)
end
local function preview_location_callback_new_signature(_, result)
return preview_location_callback(result)
end
function M.open_file()
-- Get the file currently open in the floating window
local filepath = vim.fn.expand "%:."
@ -129,7 +136,11 @@ function M.Peek(what)
else
-- Make a new request and then create the new window in the callback
local params = vim.lsp.util.make_position_params()
local success, _ = pcall(vim.lsp.buf_request, 0, "textDocument/" .. what, params, preview_location_callback)
local preview_callback = preview_location_callback_old_signature
if vim.fn.has "nvim-0.5.1" > 0 then
preview_callback = preview_location_callback_new_signature
end
local success, _ = pcall(vim.lsp.buf_request, 0, "textDocument/" .. what, params, preview_callback)
if not success then
print(
'peek: Error calling LSP method "textDocument/' .. what .. '". The current language lsp might not support it.'