summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/lsp/peek.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/lua/lsp/peek.lua b/lua/lsp/peek.lua
index dbc67417..cb00488e 100644
--- a/lua/lsp/peek.lua
+++ b/lua/lsp/peek.lua
@@ -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.'