From 3b1600d0fd5172ad9fae00987362ca0ef3d8895d Mon Sep 17 00:00:00 2001 From: Enric Lluelles Date: Fri, 2 Aug 2024 03:12:41 +0200 Subject: [PATCH] feat(lsp): support requests to many servers for some pickers (#3211) * Implement list_or_jump_all and use it * Update lua/telescope/builtin/__lsp.lua Co-authored-by: James Trew <66286082+jamestrew@users.noreply.github.com> * Make list_or_jump listen to multiple lsps at once * Don't fail early if an lsp errors --------- Co-authored-by: James Trew <66286082+jamestrew@users.noreply.github.com> --- lua/telescope/builtin/__lsp.lua | 48 ++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lua/telescope/builtin/__lsp.lua b/lua/telescope/builtin/__lsp.lua index 5d5a37831a..e63a5a7458 100644 --- a/lua/telescope/builtin/__lsp.lua +++ b/lua/telescope/builtin/__lsp.lua @@ -177,24 +177,40 @@ 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 + vim.lsp.buf_request_all(opts.bufnr, action, params, function(results_per_client) + local items = {} + local first_encoding + local errors = {} + + for client_id, result_or_error in pairs(results_per_client) do + local error, result = result_or_error.error, result_or_error.result + if error then + errors[client_id] = error + else + if result ~= nil then + local locations = {} + + if not utils.islist(result) then + vim.list_extend(locations, { result }) + else + vim.list_extend(locations, result) + end + + local offset_encoding = vim.lsp.get_client_by_id(client_id).offset_encoding + + if not vim.tbl_isempty(result) then + first_encoding = offset_encoding + end + + vim.list_extend(items, vim.lsp.util.locations_to_items(locations, offset_encoding)) + end + end end - local locations = {} - if not utils.islist(result) then - locations = { result } + for _, error in pairs(errors) do + vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. error.message) 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) @@ -225,8 +241,8 @@ local function list_or_jump(action, title, funname, params, opts) end end - local location = item_to_location(item, offset_encoding) - vim.lsp.util.jump_to_location(location, offset_encoding, opts.reuse_win) + local location = item_to_location(item, first_encoding) + vim.lsp.util.jump_to_location(location, first_encoding, opts.reuse_win) else pickers .new(opts, {