diff options
Diffstat (limited to '.config/nvim/lua/lsp/peek.lua')
-rw-r--r-- | .config/nvim/lua/lsp/peek.lua | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/.config/nvim/lua/lsp/peek.lua b/.config/nvim/lua/lsp/peek.lua index dbc6741..151c967 100644 --- a/.config/nvim/lua/lsp/peek.lua +++ b/.config/nvim/lua/lsp/peek.lua @@ -12,7 +12,8 @@ local function create_floating_file(location, opts) -- Set some defaults opts = opts or {} - local close_events = opts.close_events or { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" } + local close_events = opts.close_events + or { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" } -- location may be LocationLink or Location local uri = location.targetUri or location.uri @@ -29,7 +30,10 @@ local function create_floating_file(location, opts) local contents = vim.api.nvim_buf_get_lines( bufnr, range.start.line, - math.min(range["end"].line + 1 + (opts.context or 10), range.start.line + (opts.max_height or 15)), -- Don't let the window be more that 15 lines long(height) + math.min( + range["end"].line + 1 + (opts.context or 10), + range.start.line + (opts.max_height or 15) + ), -- Don't let the window be more that 15 lines long(height) false ) local width, height = vim.lsp.util._make_floating_popup_size(contents, opts) @@ -47,16 +51,17 @@ local function create_floating_file(location, opts) -- Set some autocmds to close the window vim.api.nvim_command( - "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)" + "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " + .. winnr + .. ", true)" ) vim.lsp.util.close_preview_autocmd(close_events, winnr) 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 +79,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,10 +142,22 @@ 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.' + 'peek: Error calling LSP method "textDocument/' + .. what + .. '". The current language lsp might not support it.' ) end end |