mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
feat(lsp): lsp.completion support set deprecated (#29882)
Problem: CompletionItem in lsp spec mentioned the deprecated attribute Solution: when item has deprecated attribute set hl_group to DiagnosticDeprecated in complete function
This commit is contained in:
@ -253,6 +253,13 @@ function M._lsp_to_complete_items(result, prefix, client_id)
|
|||||||
for _, item in ipairs(items) do
|
for _, item in ipairs(items) do
|
||||||
if matches(item) then
|
if matches(item) then
|
||||||
local word = get_completion_word(item)
|
local word = get_completion_word(item)
|
||||||
|
local hl_group = ''
|
||||||
|
if
|
||||||
|
item.deprecated
|
||||||
|
or vim.list_contains((item.tags or {}), protocol.CompletionTag.Deprecated)
|
||||||
|
then
|
||||||
|
hl_group = 'DiagnosticDeprecated'
|
||||||
|
end
|
||||||
table.insert(candidates, {
|
table.insert(candidates, {
|
||||||
word = word,
|
word = word,
|
||||||
abbr = item.label,
|
abbr = item.label,
|
||||||
@ -262,6 +269,7 @@ function M._lsp_to_complete_items(result, prefix, client_id)
|
|||||||
icase = 1,
|
icase = 1,
|
||||||
dup = 1,
|
dup = 1,
|
||||||
empty = 1,
|
empty = 1,
|
||||||
|
hl_group = hl_group,
|
||||||
user_data = {
|
user_data = {
|
||||||
nvim = {
|
nvim = {
|
||||||
lsp = {
|
lsp = {
|
||||||
|
@ -99,6 +99,13 @@ local constants = {
|
|||||||
TriggerForIncompleteCompletions = 3,
|
TriggerForIncompleteCompletions = 3,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- Completion item tags are extra annotations that tweak the rendering of a
|
||||||
|
-- completion item
|
||||||
|
CompletionTag = {
|
||||||
|
-- Render a completion as obsolete, usually using a strike-out.
|
||||||
|
Deprecated = 1,
|
||||||
|
},
|
||||||
|
|
||||||
-- A document highlight kind.
|
-- A document highlight kind.
|
||||||
DocumentHighlightKind = {
|
DocumentHighlightKind = {
|
||||||
-- A textual occurrence.
|
-- A textual occurrence.
|
||||||
@ -433,13 +440,16 @@ function protocol.make_client_capabilities()
|
|||||||
snippetSupport = true,
|
snippetSupport = true,
|
||||||
commitCharactersSupport = false,
|
commitCharactersSupport = false,
|
||||||
preselectSupport = false,
|
preselectSupport = false,
|
||||||
deprecatedSupport = false,
|
deprecatedSupport = true,
|
||||||
documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
|
documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
|
||||||
resolveSupport = {
|
resolveSupport = {
|
||||||
properties = {
|
properties = {
|
||||||
'additionalTextEdits',
|
'additionalTextEdits',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
tagSupport = {
|
||||||
|
valueSet = get_value_set(constants.CompletionTag),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
completionItemKind = {
|
completionItemKind = {
|
||||||
valueSet = get_value_set(constants.CompletionItemKind),
|
valueSet = get_value_set(constants.CompletionItemKind),
|
||||||
|
@ -307,6 +307,7 @@ describe('vim.lsp.completion: item conversion', function()
|
|||||||
info = '',
|
info = '',
|
||||||
kind = 'Module',
|
kind = 'Module',
|
||||||
menu = '',
|
menu = '',
|
||||||
|
hl_group = '',
|
||||||
word = 'this_thread',
|
word = 'this_thread',
|
||||||
}
|
}
|
||||||
local result = complete(' std::this|', completion_list)
|
local result = complete(' std::this|', completion_list)
|
||||||
@ -362,6 +363,7 @@ describe('vim.lsp.completion: item conversion', function()
|
|||||||
info = '',
|
info = '',
|
||||||
kind = 'Module',
|
kind = 'Module',
|
||||||
menu = '',
|
menu = '',
|
||||||
|
hl_group = '',
|
||||||
word = 'this_thread',
|
word = 'this_thread',
|
||||||
}
|
}
|
||||||
local result = complete(' std::this|is', completion_list)
|
local result = complete(' std::this|is', completion_list)
|
||||||
@ -529,6 +531,14 @@ describe('vim.lsp.completion: protocol', function()
|
|||||||
{
|
{
|
||||||
label = 'hello',
|
label = 'hello',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label = 'hercules',
|
||||||
|
tags = { 1 }, -- 1 represents Deprecated tag
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label = 'hero',
|
||||||
|
deprecated = true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -545,6 +555,7 @@ describe('vim.lsp.completion: protocol', function()
|
|||||||
info = '',
|
info = '',
|
||||||
kind = 'Unknown',
|
kind = 'Unknown',
|
||||||
menu = '',
|
menu = '',
|
||||||
|
hl_group = '',
|
||||||
user_data = {
|
user_data = {
|
||||||
nvim = {
|
nvim = {
|
||||||
lsp = {
|
lsp = {
|
||||||
@ -557,6 +568,50 @@ describe('vim.lsp.completion: protocol', function()
|
|||||||
},
|
},
|
||||||
word = 'hello',
|
word = 'hello',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
abbr = 'hercules',
|
||||||
|
dup = 1,
|
||||||
|
empty = 1,
|
||||||
|
icase = 1,
|
||||||
|
info = '',
|
||||||
|
kind = 'Unknown',
|
||||||
|
menu = '',
|
||||||
|
hl_group = 'DiagnosticDeprecated',
|
||||||
|
user_data = {
|
||||||
|
nvim = {
|
||||||
|
lsp = {
|
||||||
|
client_id = 1,
|
||||||
|
completion_item = {
|
||||||
|
label = 'hercules',
|
||||||
|
tags = { 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
word = 'hercules',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
abbr = 'hero',
|
||||||
|
dup = 1,
|
||||||
|
empty = 1,
|
||||||
|
icase = 1,
|
||||||
|
info = '',
|
||||||
|
kind = 'Unknown',
|
||||||
|
menu = '',
|
||||||
|
hl_group = 'DiagnosticDeprecated',
|
||||||
|
user_data = {
|
||||||
|
nvim = {
|
||||||
|
lsp = {
|
||||||
|
client_id = 1,
|
||||||
|
completion_item = {
|
||||||
|
label = 'hero',
|
||||||
|
deprecated = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
word = 'hero',
|
||||||
|
},
|
||||||
}, matches)
|
}, matches)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user