Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch results from multiple LSPs #3211

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions lua/telescope/builtin/__lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,36 @@ 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
vim.lsp.buf_request_all(opts.bufnr, action, params, function(results_per_client)
local items = {}
local first_encoding

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
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. error.message)
return
end
enriclluelles marked this conversation as resolved.
Show resolved Hide resolved

if result == nil then
return
end
if result ~= nil then
local locations = {}

local locations = {}
if not utils.islist(result) then
locations = { result }
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
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)

Expand Down Expand Up @@ -225,8 +237,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, {
Expand Down
Loading