aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2024-07-31 22:15:34 +0800
committerGitHub <noreply@github.com>2024-07-31 16:15:34 +0200
commit4e90bc30237ae81bf15e77c17ac8089a2cc74046 (patch)
tree1a11de1e060570c562fbe59092322ddec45e6be9
parent573a71469d37cc35f72bfc929f4ce1156833df9f (diff)
downloadrneovim-4e90bc30237ae81bf15e77c17ac8089a2cc74046.tar.gz
rneovim-4e90bc30237ae81bf15e77c17ac8089a2cc74046.tar.bz2
rneovim-4e90bc30237ae81bf15e77c17ac8089a2cc74046.zip
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
-rw-r--r--runtime/lua/vim/lsp/completion.lua8
-rw-r--r--runtime/lua/vim/lsp/protocol.lua12
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua55
3 files changed, 74 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index 1078e3eb7e..6a6659fd25 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -253,6 +253,13 @@ function M._lsp_to_complete_items(result, prefix, client_id)
for _, item in ipairs(items) do
if matches(item) then
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, {
word = word,
abbr = item.label,
@@ -262,6 +269,7 @@ function M._lsp_to_complete_items(result, prefix, client_id)
icase = 1,
dup = 1,
empty = 1,
+ hl_group = hl_group,
user_data = {
nvim = {
lsp = {
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 656921644d..b53f9a207a 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -99,6 +99,13 @@ local constants = {
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.
DocumentHighlightKind = {
-- A textual occurrence.
@@ -433,13 +440,16 @@ function protocol.make_client_capabilities()
snippetSupport = true,
commitCharactersSupport = false,
preselectSupport = false,
- deprecatedSupport = false,
+ deprecatedSupport = true,
documentationFormat = { constants.MarkupKind.Markdown, constants.MarkupKind.PlainText },
resolveSupport = {
properties = {
'additionalTextEdits',
},
},
+ tagSupport = {
+ valueSet = get_value_set(constants.CompletionTag),
+ },
},
completionItemKind = {
valueSet = get_value_set(constants.CompletionItemKind),
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index 5c2933c610..aad7e350ee 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -307,6 +307,7 @@ describe('vim.lsp.completion: item conversion', function()
info = '',
kind = 'Module',
menu = '',
+ hl_group = '',
word = 'this_thread',
}
local result = complete(' std::this|', completion_list)
@@ -362,6 +363,7 @@ describe('vim.lsp.completion: item conversion', function()
info = '',
kind = 'Module',
menu = '',
+ hl_group = '',
word = 'this_thread',
}
local result = complete(' std::this|is', completion_list)
@@ -529,6 +531,14 @@ describe('vim.lsp.completion: protocol', function()
{
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 = '',
kind = 'Unknown',
menu = '',
+ hl_group = '',
user_data = {
nvim = {
lsp = {
@@ -557,6 +568,50 @@ describe('vim.lsp.completion: protocol', function()
},
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)
end)
end)