mirror of
https://github.com/neovim/neovim.git
synced 2025-10-22 17:11:49 +00:00
feat(lsp): handle deprecated document symbols (#34751)
This commit is contained in:

committed by
GitHub

parent
580b8cfac7
commit
957093da0d
@@ -144,6 +144,11 @@ local constants = {
|
|||||||
TypeParameter = 26,
|
TypeParameter = 26,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- Extra annotations that tweak the rendering of a symbol.
|
||||||
|
SymbolTag = {
|
||||||
|
Deprecated = 1,
|
||||||
|
},
|
||||||
|
|
||||||
-- Represents reasons why a text document is saved.
|
-- Represents reasons why a text document is saved.
|
||||||
TextDocumentSaveReason = {
|
TextDocumentSaveReason = {
|
||||||
-- Manually triggered, e.g. by the user pressing save, by starting debugging,
|
-- Manually triggered, e.g. by the user pressing save, by starting debugging,
|
||||||
@@ -525,6 +530,9 @@ function protocol.make_client_capabilities()
|
|||||||
valueSet = get_value_set(constants.SymbolKind),
|
valueSet = get_value_set(constants.SymbolKind),
|
||||||
},
|
},
|
||||||
hierarchicalDocumentSymbolSupport = true,
|
hierarchicalDocumentSymbolSupport = true,
|
||||||
|
tagSupport = {
|
||||||
|
valueSet = get_value_set(constants.SymbolTag),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rename = {
|
rename = {
|
||||||
dynamicRegistration = true,
|
dynamicRegistration = true,
|
||||||
|
@@ -1892,6 +1892,11 @@ function M.symbols_to_items(symbols, bufnr, position_encoding)
|
|||||||
local end_lnum = range['end'].line + 1
|
local end_lnum = range['end'].line + 1
|
||||||
local end_col = get_line_byte_from_position(bufnr, range['end'], position_encoding) + 1
|
local end_col = get_line_byte_from_position(bufnr, range['end'], position_encoding) + 1
|
||||||
|
|
||||||
|
local is_deprecated = symbol.deprecated
|
||||||
|
or (symbol.tags and vim.tbl_contains(symbol.tags, protocol.SymbolTag.Deprecated))
|
||||||
|
local text =
|
||||||
|
string.format('[%s] %s%s', kind, symbol.name, is_deprecated and ' (deprecated)' or '')
|
||||||
|
|
||||||
items[#items + 1] = {
|
items[#items + 1] = {
|
||||||
filename = filename,
|
filename = filename,
|
||||||
lnum = lnum,
|
lnum = lnum,
|
||||||
@@ -1899,7 +1904,7 @@ function M.symbols_to_items(symbols, bufnr, position_encoding)
|
|||||||
end_lnum = end_lnum,
|
end_lnum = end_lnum,
|
||||||
end_col = end_col,
|
end_col = end_col,
|
||||||
kind = kind,
|
kind = kind,
|
||||||
text = '[' .. kind .. '] ' .. symbol.name,
|
text = text,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -3234,6 +3234,89 @@ describe('LSP', function()
|
|||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('handles deprecated items', function()
|
||||||
|
local expected = {
|
||||||
|
{
|
||||||
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 2,
|
||||||
|
filename = '',
|
||||||
|
kind = 'File',
|
||||||
|
lnum = 2,
|
||||||
|
text = '[File] TestA (deprecated)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
col = 1,
|
||||||
|
end_col = 1,
|
||||||
|
end_lnum = 6,
|
||||||
|
filename = '',
|
||||||
|
kind = 'Namespace',
|
||||||
|
lnum = 6,
|
||||||
|
text = '[Namespace] TestC (deprecated)',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
eq(
|
||||||
|
expected,
|
||||||
|
exec_lua(function()
|
||||||
|
local doc_syms = {
|
||||||
|
{
|
||||||
|
deprecated = true,
|
||||||
|
detail = 'A',
|
||||||
|
kind = 1,
|
||||||
|
name = 'TestA',
|
||||||
|
range = {
|
||||||
|
start = {
|
||||||
|
character = 0,
|
||||||
|
line = 1,
|
||||||
|
},
|
||||||
|
['end'] = {
|
||||||
|
character = 0,
|
||||||
|
line = 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
selectionRange = {
|
||||||
|
start = {
|
||||||
|
character = 0,
|
||||||
|
line = 1,
|
||||||
|
},
|
||||||
|
['end'] = {
|
||||||
|
character = 4,
|
||||||
|
line = 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail = 'C',
|
||||||
|
kind = 3,
|
||||||
|
name = 'TestC',
|
||||||
|
range = {
|
||||||
|
start = {
|
||||||
|
character = 0,
|
||||||
|
line = 5,
|
||||||
|
},
|
||||||
|
['end'] = {
|
||||||
|
character = 0,
|
||||||
|
line = 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
selectionRange = {
|
||||||
|
start = {
|
||||||
|
character = 0,
|
||||||
|
line = 5,
|
||||||
|
},
|
||||||
|
['end'] = {
|
||||||
|
character = 4,
|
||||||
|
line = 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tags = { 1 }, -- deprecated
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return vim.lsp.util.symbols_to_items(doc_syms, nil, 'utf-16')
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('convert SymbolInformation[] to items', function()
|
it('convert SymbolInformation[] to items', function()
|
||||||
|
Reference in New Issue
Block a user