From 45929d9d82b10e48a6408fe42cd4fd6cc59e19ac Mon Sep 17 00:00:00 2001 From: Enric Lluelles Date: Mon, 22 Jul 2024 12:57:56 +0200 Subject: [PATCH] Make list_or_jump listen to multiple lsps at once --- lua/telescope/builtin/__lsp.lua | 88 ++------------------------------- 1 file changed, 5 insertions(+), 83 deletions(-) diff --git a/lua/telescope/builtin/__lsp.lua b/lua/telescope/builtin/__lsp.lua index 19ed375e74..237c2fa149 100644 --- a/lua/telescope/builtin/__lsp.lua +++ b/lua/telescope/builtin/__lsp.lua @@ -173,7 +173,7 @@ end ---@param funname string: name of the calling function ---@param params lsp.TextDocumentPositionParams ---@param opts table -local function list_or_jump_all(action, title, funname, params, opts) +local function list_or_jump(action, title, funname, params, opts) opts.reuse_win = vim.F.if_nil(opts.reuse_win, false) opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr) @@ -241,83 +241,6 @@ local function list_or_jump_all(action, title, funname, params, opts) local location = item_to_location(item, first_encoding) vim.lsp.util.jump_to_location(location, first_encoding, opts.reuse_win) - else - pickers - .new(opts, { - prompt_title = title, - finder = finders.new_table { - results = items, - entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts), - }, - previewer = conf.qflist_previewer(opts), - sorter = conf.generic_sorter(opts), - push_cursor_on_edit = true, - push_tagstack_on_edit = true, - }) - :find() - end - end) -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 opts table -local function list_or_jump(action, title, funname, params, opts) - opts.reuse_win = vim.F.if_nil(opts.reuse_win, false) - opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr) - - vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _) - if err then - vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message) - return - end - - if result == nil then - return - end - - local locations = {} - if not utils.islist(result) then - locations = { result } - end - vim.list_extend(locations, result) - - local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding - local items = vim.lsp.util.locations_to_items(locations, offset_encoding) - items = apply_action_handler(action, items, opts) - items = filter_file_ignore_patters(items, opts) - - if vim.tbl_isempty(items) then - utils.notify(funname, { - msg = string.format("No %s found", title), - level = "INFO", - }) - return - end - - if #items == 1 and opts.jump_type ~= "never" then - local item = items[1] - if opts.curr_filepath ~= item.filename then - local cmd - if opts.jump_type == "tab" then - cmd = "tabedit" - elseif opts.jump_type == "split" then - cmd = "new" - elseif opts.jump_type == "vsplit" then - cmd = "vnew" - elseif opts.jump_type == "tab drop" then - cmd = "tab drop" - end - - if cmd then - vim.cmd(string.format("%s %s", cmd, item.filename)) - end - end - - local location = item_to_location(item, offset_encoding) - vim.lsp.util.jump_to_location(location, offset_encoding, opts.reuse_win) else pickers .new(opts, { @@ -340,17 +263,17 @@ lsp.references = function(opts) opts.include_current_line = vim.F.if_nil(opts.include_current_line, false) local params = vim.lsp.util.make_position_params(opts.winnr) params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) } - return list_or_jump_all("textDocument/references", "LSP References", "builtin.lsp_references", params, opts) + 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) - return list_or_jump_all("textDocument/definition", "LSP Definitions", "builtin.lsp_definitions", params, opts) + 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) - return list_or_jump_all( + return list_or_jump( "textDocument/typeDefinition", "LSP Type Definitions", "builtin.lsp_type_definitions", @@ -361,8 +284,7 @@ end lsp.implementations = function(opts) local params = vim.lsp.util.make_position_params(opts.winnr) - return list_or_jump_all("textDocument/implementation", "LSP Implementations", "builtin.lsp_implementations", params, - opts) + return list_or_jump("textDocument/implementation", "LSP Implementations", "builtin.lsp_implementations", params, opts) end local symbols_sorter = function(symbols)