Skip to content

Commit 3b1600d

Browse files
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 <[email protected]> * Make list_or_jump listen to multiple lsps at once * Don't fail early if an lsp errors --------- Co-authored-by: James Trew <[email protected]>
1 parent 10b8a82 commit 3b1600d

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

lua/telescope/builtin/__lsp.lua

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,40 @@ local function list_or_jump(action, title, funname, params, opts)
177177
opts.reuse_win = vim.F.if_nil(opts.reuse_win, false)
178178
opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr)
179179

180-
vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _)
181-
if err then
182-
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message)
183-
return
184-
end
185-
186-
if result == nil then
187-
return
180+
vim.lsp.buf_request_all(opts.bufnr, action, params, function(results_per_client)
181+
local items = {}
182+
local first_encoding
183+
local errors = {}
184+
185+
for client_id, result_or_error in pairs(results_per_client) do
186+
local error, result = result_or_error.error, result_or_error.result
187+
if error then
188+
errors[client_id] = error
189+
else
190+
if result ~= nil then
191+
local locations = {}
192+
193+
if not utils.islist(result) then
194+
vim.list_extend(locations, { result })
195+
else
196+
vim.list_extend(locations, result)
197+
end
198+
199+
local offset_encoding = vim.lsp.get_client_by_id(client_id).offset_encoding
200+
201+
if not vim.tbl_isempty(result) then
202+
first_encoding = offset_encoding
203+
end
204+
205+
vim.list_extend(items, vim.lsp.util.locations_to_items(locations, offset_encoding))
206+
end
207+
end
188208
end
189209

190-
local locations = {}
191-
if not utils.islist(result) then
192-
locations = { result }
210+
for _, error in pairs(errors) do
211+
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. error.message)
193212
end
194-
vim.list_extend(locations, result)
195213

196-
local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding
197-
local items = vim.lsp.util.locations_to_items(locations, offset_encoding)
198214
items = apply_action_handler(action, items, opts)
199215
items = filter_file_ignore_patters(items, opts)
200216

@@ -225,8 +241,8 @@ local function list_or_jump(action, title, funname, params, opts)
225241
end
226242
end
227243

228-
local location = item_to_location(item, offset_encoding)
229-
vim.lsp.util.jump_to_location(location, offset_encoding, opts.reuse_win)
244+
local location = item_to_location(item, first_encoding)
245+
vim.lsp.util.jump_to_location(location, first_encoding, opts.reuse_win)
230246
else
231247
pickers
232248
.new(opts, {

0 commit comments

Comments
 (0)