diff options
author | Yi Ming <ofseed@foxmail.com> | 2025-02-11 17:19:44 +0800 |
---|---|---|
committer | Yi Ming <ofseed@foxmail.com> | 2025-02-11 18:48:56 +0800 |
commit | e8b5dd1e89bfa984e7b943443a291484cba23fac (patch) | |
tree | 3d8419bb98c6b2a951bc994e30dd26bd7008f690 /runtime/lua/vim | |
parent | 67221497762ab5a055451c40a374e03bb620a68a (diff) | |
download | rneovim-e8b5dd1e89bfa984e7b943443a291484cba23fac.tar.gz rneovim-e8b5dd1e89bfa984e7b943443a291484cba23fac.tar.bz2 rneovim-e8b5dd1e89bfa984e7b943443a291484cba23fac.zip |
feat(lsp)!: `symbol_to_item` requires `offset_encoding`
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 5 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 17 |
2 files changed, 16 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index b35140dfad..25f87a7164 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -231,7 +231,7 @@ end --- --- The returned function has an optional {config} parameter that accepts |vim.lsp.ListOpts| --- ----@param map_result fun(resp, bufnr: integer): table to convert the response +---@param map_result fun(resp, bufnr: integer, position_encoding: 'utf-8'|'utf-16'|'utf-32'): table to convert the response ---@param entity string name of the resource used in a `not found` error message ---@param title_fn fun(ctx: lsp.HandlerContext): string Function to call to generate list title ---@return lsp.Handler @@ -244,7 +244,8 @@ local function response_to_list(map_result, entity, title_fn) end config = config or {} local title = title_fn(ctx) - local items = map_result(result, ctx.bufnr) + local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) + local items = map_result(result, ctx.bufnr, client.offset_encoding) local list = { title = title, items = items, context = ctx } if config.on_list then diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index e0d93ca75b..86c0a2b3db 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1777,9 +1777,18 @@ end --- ---@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[] list of symbols ---@param bufnr? integer buffer handle or 0 for current, defaults to current +---@param position_encoding? 'utf-8'|'utf-16'|'utf-32' +--- default to first client of buffer ---@return vim.quickfix.entry[] # See |setqflist()| for the format -function M.symbols_to_items(symbols, bufnr) +function M.symbols_to_items(symbols, bufnr, position_encoding) bufnr = vim._resolve_bufnr(bufnr) + if position_encoding == nil then + vim.notify_once( + 'symbols_to_items must be called with valid position encoding', + vim.log.levels.WARN + ) + position_encoding = vim.lsp.get_clients({ bufnr = 0 })[1].offset_encoding + end local items = {} --- @type vim.quickfix.entry[] for _, symbol in ipairs(symbols) do @@ -1800,9 +1809,9 @@ function M.symbols_to_items(symbols, bufnr) local kind = protocol.SymbolKind[symbol.kind] or 'Unknown' local lnum = range['start'].line + 1 - local col = range['start'].character + 1 + local col = get_line_byte_from_position(bufnr, range['start'], position_encoding) + 1 local end_lnum = range['end'].line + 1 - local end_col = range['end'].character + 1 + local end_col = get_line_byte_from_position(bufnr, range['end'], position_encoding) + 1 items[#items + 1] = { filename = filename, @@ -1816,7 +1825,7 @@ function M.symbols_to_items(symbols, bufnr) end if symbol.children then - list_extend(items, M.symbols_to_items(symbol.children, bufnr)) + list_extend(items, M.symbols_to_items(symbol.children, bufnr, position_encoding)) end end |