mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
feat(lsp)!: location_to_items
and symbol_to_item
require offset_encoding
This commit is contained in:
parent
7c64dc833c
commit
99b6c39926
@ -2380,12 +2380,14 @@ stylize_markdown({bufnr}, {contents}, {opts})
|
|||||||
Return: ~
|
Return: ~
|
||||||
(`table`) stripped content
|
(`table`) stripped content
|
||||||
|
|
||||||
symbols_to_items({symbols}, {bufnr}) *vim.lsp.util.symbols_to_items()*
|
*vim.lsp.util.symbols_to_items()*
|
||||||
|
symbols_to_items({symbols}, {bufnr}, {position_encoding})
|
||||||
Converts symbols to quickfix list items.
|
Converts symbols to quickfix list items.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]`)
|
• {symbols} (`lsp.DocumentSymbol[]|lsp.SymbolInformation[]`)
|
||||||
• {bufnr} (`integer?`)
|
• {bufnr} (`integer?`)
|
||||||
|
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(`vim.quickfix.entry[]`) See |setqflist()| for the format
|
(`vim.quickfix.entry[]`) See |setqflist()| for the format
|
||||||
|
@ -110,6 +110,8 @@ LSP
|
|||||||
• |vim.lsp.util.make_position_params()|, |vim.lsp.util.make_range_params()|
|
• |vim.lsp.util.make_position_params()|, |vim.lsp.util.make_range_params()|
|
||||||
and |vim.lsp.util.make_given_range_params()| now require the `position_encoding`
|
and |vim.lsp.util.make_given_range_params()| now require the `position_encoding`
|
||||||
parameter.
|
parameter.
|
||||||
|
• |vim.lsp.util.location_to_items| and |vim.lsp.util.symbols_to_items()| now
|
||||||
|
requires the `position_encoding` parameter.
|
||||||
|
|
||||||
LUA
|
LUA
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ end
|
|||||||
---
|
---
|
||||||
--- The returned function has an optional {config} parameter that accepts |vim.lsp.ListOpts|
|
--- 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 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
|
---@param title_fn fun(ctx: lsp.HandlerContext): string Function to call to generate list title
|
||||||
---@return lsp.Handler
|
---@return lsp.Handler
|
||||||
@ -244,7 +244,8 @@ local function response_to_list(map_result, entity, title_fn)
|
|||||||
end
|
end
|
||||||
config = config or {}
|
config = config or {}
|
||||||
local title = title_fn(ctx)
|
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 }
|
local list = { title = title, items = items, context = ctx }
|
||||||
if config.loclist then
|
if config.loclist then
|
||||||
|
@ -1774,9 +1774,19 @@ end
|
|||||||
---
|
---
|
||||||
---@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[]
|
---@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[]
|
||||||
---@param bufnr? integer
|
---@param bufnr? integer
|
||||||
|
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||||
---@return vim.quickfix.entry[] # See |setqflist()| for the format
|
---@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 = bufnr or 0
|
bufnr = bufnr or 0
|
||||||
|
if position_encoding == nil then
|
||||||
|
vim.notify_once(
|
||||||
|
'symbols_to_items must be called with valid position encoding',
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
local clients = vim.lsp.get_clients({ bufnr = bufnr })
|
||||||
|
position_encoding = vim.tbl_isempty(clients) and 'utf-16' or clients[1].offset_encoding
|
||||||
|
end
|
||||||
|
|
||||||
local items = {} --- @type vim.quickfix.entry[]
|
local items = {} --- @type vim.quickfix.entry[]
|
||||||
for _, symbol in ipairs(symbols) do
|
for _, symbol in ipairs(symbols) do
|
||||||
--- @type string?, lsp.Range?
|
--- @type string?, lsp.Range?
|
||||||
@ -1796,9 +1806,9 @@ function M.symbols_to_items(symbols, bufnr)
|
|||||||
local kind = protocol.SymbolKind[symbol.kind] or 'Unknown'
|
local kind = protocol.SymbolKind[symbol.kind] or 'Unknown'
|
||||||
|
|
||||||
local lnum = range['start'].line + 1
|
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_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] = {
|
items[#items + 1] = {
|
||||||
filename = filename,
|
filename = filename,
|
||||||
@ -1812,7 +1822,7 @@ function M.symbols_to_items(symbols, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if symbol.children then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2916,6 +2916,8 @@ describe('LSP', function()
|
|||||||
local expected = {
|
local expected = {
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 2,
|
||||||
filename = '',
|
filename = '',
|
||||||
kind = 'File',
|
kind = 'File',
|
||||||
lnum = 2,
|
lnum = 2,
|
||||||
@ -2923,6 +2925,8 @@ describe('LSP', function()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 4,
|
||||||
filename = '',
|
filename = '',
|
||||||
kind = 'Module',
|
kind = 'Module',
|
||||||
lnum = 4,
|
lnum = 4,
|
||||||
@ -2930,6 +2934,8 @@ describe('LSP', function()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 6,
|
||||||
filename = '',
|
filename = '',
|
||||||
kind = 'Namespace',
|
kind = 'Namespace',
|
||||||
lnum = 6,
|
lnum = 6,
|
||||||
@ -3031,6 +3037,8 @@ describe('LSP', function()
|
|||||||
local expected = {
|
local expected = {
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 2,
|
||||||
filename = '',
|
filename = '',
|
||||||
kind = 'File',
|
kind = 'File',
|
||||||
lnum = 2,
|
lnum = 2,
|
||||||
@ -3038,6 +3046,8 @@ describe('LSP', function()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 6,
|
||||||
filename = '',
|
filename = '',
|
||||||
kind = 'Namespace',
|
kind = 'Namespace',
|
||||||
lnum = 6,
|
lnum = 6,
|
||||||
@ -3111,6 +3121,8 @@ describe('LSP', function()
|
|||||||
local expected = {
|
local expected = {
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 3,
|
||||||
filename = '/test_a',
|
filename = '/test_a',
|
||||||
kind = 'File',
|
kind = 'File',
|
||||||
lnum = 2,
|
lnum = 2,
|
||||||
@ -3118,6 +3130,8 @@ describe('LSP', function()
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
col = 1,
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 5,
|
||||||
filename = '/test_b',
|
filename = '/test_b',
|
||||||
kind = 'Module',
|
kind = 'Module',
|
||||||
lnum = 4,
|
lnum = 4,
|
||||||
|
Loading…
Reference in New Issue
Block a user