Skip to content

Commit a17d611

Browse files
fix(lsp): add default position encoding when calling symbols_to_items() (nvim-telescope#3418)
1 parent 814f102 commit a17d611

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

lua/telescope/builtin/__lsp.lua

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ end
345345

346346
lsp.document_symbols = function(opts)
347347
local params = client_position_params(opts.winnr)
348-
vim.lsp.buf_request(opts.bufnr, "textDocument/documentSymbol", params, function(err, result, _, _)
348+
vim.lsp.buf_request(opts.bufnr, "textDocument/documentSymbol", params, function(err, result, ctx, _)
349349
if err then
350350
vim.api.nvim_err_writeln("Error when finding document symbols: " .. err.message)
351351
return
@@ -359,7 +359,14 @@ lsp.document_symbols = function(opts)
359359
return
360360
end
361361

362-
local locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {}
362+
local locations
363+
if vim.fn.has "nvim-0.11" == 1 then
364+
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
365+
locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr, client.offset_encoding) or {}
366+
else
367+
locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {}
368+
end
369+
363370
locations = utils.filter_symbols(locations, opts, symbols_sorter)
364371
if vim.tbl_isempty(locations) then
365372
-- error message already printed in `utils.filter_symbols`
@@ -396,13 +403,20 @@ end
396403

397404
lsp.workspace_symbols = function(opts)
398405
local params = { query = opts.query or "" }
399-
vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, _, _)
406+
vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, ctx, _)
400407
if err then
401408
vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message)
402409
return
403410
end
404411

405-
local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {}
412+
local locations
413+
if vim.fn.has "nvim-0.11" == 1 then
414+
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
415+
locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr, client.offset_encoding) or {}
416+
else
417+
locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {}
418+
end
419+
406420
locations = utils.filter_symbols(locations, opts, symbols_sorter)
407421
if vim.tbl_isempty(locations) then
408422
-- error message already printed in `utils.filter_symbols`
@@ -448,11 +462,16 @@ local function get_workspace_symbols_requester(bufnr, opts)
448462
local results = rx() ---@type table<integer, {error: lsp.ResponseError?, result: lsp.WorkspaceSymbol?}>
449463
local locations = {} ---@type vim.quickfix.entry[]
450464

451-
for _, client_res in pairs(results) do
465+
for client_id, client_res in pairs(results) do
452466
if client_res.error then
453467
vim.api.nvim_err_writeln("Error when executing workspace/symbol : " .. client_res.error.message)
454468
elseif client_res.result ~= nil then
455-
vim.list_extend(locations, vim.lsp.util.symbols_to_items(client_res.result, bufnr))
469+
if vim.fn.has "nvim-0.11" == 1 then
470+
local client = assert(vim.lsp.get_client_by_id(client_id))
471+
vim.list_extend(locations, vim.lsp.util.symbols_to_items(client_res.result, bufnr, client.offset_encoding))
472+
else
473+
vim.list_extend(locations, vim.lsp.util.symbols_to_items(client_res.result, bufnr))
474+
end
456475
end
457476
end
458477

0 commit comments

Comments
 (0)