diff --git a/lua/telescope/builtin/__lsp.lua b/lua/telescope/builtin/__lsp.lua index 4f37c58458..5461d4aa32 100644 --- a/lua/telescope/builtin/__lsp.lua +++ b/lua/telescope/builtin/__lsp.lua @@ -68,8 +68,26 @@ local function pick_call_hierarchy_item(call_hierarchy_items) return call_hierarchy_items[choice] end +local function client_position_params(win, extra) + win = win or vim.api.nvim_get_current_win() + if not vim.fn.has("nvim-0.11") then + local params = vim.lsp.util.make_position_params(win) + if extra then + params = vim.tbl_extend('force', params, extra) + end + return params + end + return function(client) + local ret = vim.api.util.make_position_params(win, client.offset_encoding) + if extra then + ret = vim.tbl_extend('force', ret, extra) + end + return ret + end +end + local function calls(opts, direction) - local params = vim.lsp.util.make_position_params() + local params = client_position_params(vim.api.nvim_get_current_win()) vim.lsp.buf_request(opts.bufnr, "textDocument/prepareCallHierarchy", params, function(err, result) if err then vim.api.nvim_err_writeln("Error when preparing call hierarchy: " .. err) @@ -171,7 +189,7 @@ end ---@param action telescope.lsp.list_or_jump_action ---@param title string prompt title ---@param funname string: name of the calling function ----@param params lsp.TextDocumentPositionParams +---@param params lsp.TextDocumentPositionParams|(fun(client: vim.lsp.Client, bufnr: integer): table?) ---@param opts table local function list_or_jump(action, title, funname, params, opts) opts.reuse_win = vim.F.if_nil(opts.reuse_win, false) @@ -263,19 +281,19 @@ end lsp.references = function(opts) opts.include_current_line = vim.F.if_nil(opts.include_current_line, false) - ---@class lsp.TextDocumentPositionParams - local params = vim.lsp.util.make_position_params(opts.winnr) - params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) } + local params = client_position_params(vim.api.nvim_get_current_win(), { + context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) } + }) return list_or_jump("textDocument/references", "LSP References", "builtin.lsp_references", params, opts) end lsp.definitions = function(opts) - local params = vim.lsp.util.make_position_params(opts.winnr) + local params = client_position_params(opts.winnr) return list_or_jump("textDocument/definition", "LSP Definitions", "builtin.lsp_definitions", params, opts) end lsp.type_definitions = function(opts) - local params = vim.lsp.util.make_position_params(opts.winnr) + local params = client_position_params(opts.winnr) return list_or_jump( "textDocument/typeDefinition", "LSP Type Definitions", @@ -286,8 +304,14 @@ lsp.type_definitions = function(opts) end lsp.implementations = function(opts) - local params = vim.lsp.util.make_position_params(opts.winnr) - return list_or_jump("textDocument/implementation", "LSP Implementations", "builtin.lsp_implementations", params, opts) + local params = client_position_params(opts.winnr) + return list_or_jump( + "textDocument/implementation", + "LSP Implementations", + "builtin.lsp_implementations", + params, + opts + ) end local symbols_sorter = function(symbols) @@ -323,7 +347,7 @@ local symbols_sorter = function(symbols) end lsp.document_symbols = function(opts) - local params = vim.lsp.util.make_position_params(opts.winnr) + local params = client_position_params(opts.winnr) vim.lsp.buf_request(opts.bufnr, "textDocument/documentSymbol", params, function(err, result, _, _) if err then vim.api.nvim_err_writeln("Error when finding document symbols: " .. err.message)