Skip to content

Commit

Permalink
refactor(lsp): deprecate completion util methods
Browse files Browse the repository at this point in the history
Relates to #25272
  • Loading branch information
mfussenegger committed Oct 21, 2023
1 parent 1e10310 commit 195301c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 62 deletions.
3 changes: 3 additions & 0 deletions runtime/doc/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ LSP FUNCTIONS
- *vim.lsp.util.trim_empty_lines()* Use |vim.split()| with `trimempty` instead.
- *vim.lsp.util.try_trim_markdown_code_blocks()*
- *vim.lsp.util.set_lines()*
- *vim.lsp.util.extract_completion_items()*
- *vim.lsp.util.parse_snippet()*
- *vim.lsp.util.text_document_completion_list_to_complete_items()*

TREESITTER FUNCTIONS
- *vim.treesitter.language.require_language()* Use |vim.treesitter.language.add()|
Expand Down
39 changes: 0 additions & 39 deletions runtime/doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1711,19 +1711,6 @@ convert_signature_help_to_markdown_lines({signature_help}, {ft}, {triggers})
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp

*vim.lsp.util.extract_completion_items()*
extract_completion_items({result})
Can be used to extract the completion items from a `textDocument/completion` request, which may return one of `CompletionItem[]` , `CompletionList` or null.

Parameters: ~
{result} (table) The result of a `textDocument/completion` request

Return: ~
lsp.CompletionItem[] List of completion items

See also: ~
https://microsoft.github.io/language-server-protocol/specification#textDocument_completion

get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
Returns indentation size.

Expand Down Expand Up @@ -1925,15 +1912,6 @@ open_floating_preview({contents}, {syntax}, {opts})
(integer) bufnr of newly created float window
(integer) winid of newly created float window preview window

parse_snippet({input}) *vim.lsp.util.parse_snippet()*
Parses snippets in a completion entry.

Parameters: ~
{input} (string) unparsed snippet

Return: ~
(string) parsed snippet

preview_location({location}, {opts}) *vim.lsp.util.preview_location()*
Previews a location in a floating window

Expand Down Expand Up @@ -2002,23 +1980,6 @@ symbols_to_items({symbols}, {bufnr}) *vim.lsp.util.symbols_to_items()*
Parameters: ~
{symbols} (table) DocumentSymbol[] or SymbolInformation[]

*vim.lsp.util.text_document_completion_list_to_complete_items()*
text_document_completion_list_to_complete_items({result}, {prefix})
Turns the result of a `textDocument/completion` request into
vim-compatible |complete-items|.

Parameters: ~
{result} (table) The result of a `textDocument/completion` call, e.g.
from |vim.lsp.buf.completion()|, which may be one of
`CompletionItem[]`, `CompletionList` or `null`
{prefix} (string) the prefix to filter the completion items

Return: ~
table[] items

See also: ~
• complete-items


==============================================================================
Lua module: vim.lsp.log *lsp-log*
Expand Down
3 changes: 3 additions & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ release.
- |vim.lsp.util.trim_empty_lines()| Use |vim.split()| with `trimempty` instead.
- |vim.lsp.util.try_trim_markdown_code_blocks()|
- |vim.lsp.util.set_lines()|
- |vim.lsp.util.extract_completion_items()|
- |vim.lsp.util.parse_snippet()|
- |vim.lsp.util.text_document_completion_list_to_complete_items()|

`vim.loop` has been renamed to `vim.uv`.

Expand Down
17 changes: 6 additions & 11 deletions runtime/lua/vim/lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,12 @@ end
--- Can be used to extract the completion items from a
--- `textDocument/completion` request, which may return one of
--- `CompletionItem[]`, `CompletionList` or null.
---@deprecated
---@param result table The result of a `textDocument/completion` request
---@return lsp.CompletionItem[] List of completion items
---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
function M.extract_completion_items(result)
vim.deprecate('vim.lsp.util.extract_completion_items', nil, '0.11')
if type(result) == 'table' and result.items then
-- result is a `CompletionList`
return result.items
Expand Down Expand Up @@ -606,9 +608,11 @@ end

--- Parses snippets in a completion entry.
---
---@deprecated
---@param input string unparsed snippet
---@return string parsed snippet
function M.parse_snippet(input)
vim.deprecate('vim.lsp.util.parse_snippet', nil, '0.11')
local ok, parsed = pcall(function()
return snippet.parse(input)
end)
Expand All @@ -619,27 +623,18 @@ function M.parse_snippet(input)
return tostring(parsed)
end

--- According to LSP spec, if the client set `completionItemKind.valueSet`,
--- the client must handle it properly even if it receives a value outside the
--- specification.
---
---@param completion_item_kind (`vim.lsp.protocol.completionItemKind`)
---@return (`vim.lsp.protocol.completionItemKind`)
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
function M._get_completion_item_kind_name(completion_item_kind)
return protocol.CompletionItemKind[completion_item_kind] or 'Unknown'
end

--- Turns the result of a `textDocument/completion` request into vim-compatible
--- |complete-items|.
---
---@deprecated
---@param result table The result of a `textDocument/completion` call, e.g.
--- from |vim.lsp.buf.completion()|, which may be one of `CompletionItem[]`,
--- `CompletionList` or `null`
---@param prefix (string) the prefix to filter the completion items
---@return table[] items
---@see complete-items
function M.text_document_completion_list_to_complete_items(result, prefix)
vim.deprecate('vim.lsp.util.text_document_completion_list_to_complete_items', nil, '0.11')
return require('vim.lsp._completion')._lsp_to_complete_items(result, prefix)
end

Expand Down
12 changes: 0 additions & 12 deletions test/functional/plugin/lsp_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2769,18 +2769,6 @@ describe('LSP', function()
end)
end)

describe('lsp.util._get_completion_item_kind_name', function()
it('returns the name specified by protocol', function()
eq("Text", exec_lua("return vim.lsp.util._get_completion_item_kind_name(1)"))
eq("TypeParameter", exec_lua("return vim.lsp.util._get_completion_item_kind_name(25)"))
end)
it('returns the name not specified by protocol', function()
eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(nil)"))
eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(vim.NIL)"))
eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(1000)"))
end)
end)

describe('lsp.util._get_symbol_kind_name', function()
it('returns the name specified by protocol', function()
eq("File", exec_lua("return vim.lsp.util._get_symbol_kind_name(1)"))
Expand Down

0 comments on commit 195301c

Please sign in to comment.