mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +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 | ||||
|     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 = { | ||||
|   | ||||
| @@ -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), | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 glepnir
					glepnir