Skip to content

Commit

Permalink
fix(lsp): deprecate vim.lsp.omnifunc
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaSolOs committed May 24, 2024
1 parent 4d05677 commit 8730bec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
2 changes: 2 additions & 0 deletions runtime/doc/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ LSP FUNCTIONS
{async=false} instead.
- *vim.lsp.buf.range_formatting()* Use |vim.lsp.formatexpr()|
or |vim.lsp.buf.format()| instead.
- *vim.lsp.omnifunc()* Use |vim.lsp.completion.omnifunc()|
instead.

LUA
- vim.register_keystroke_callback() Use |vim.on_key()| instead.
Expand Down
27 changes: 5 additions & 22 deletions runtime/doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ listed below, if (1) the language server supports the functionality and (2)
the options are empty or were set by the builtin runtime (ftplugin) files. The
options are not restored when the LSP client is stopped or detached.

- 'omnifunc' is set to |vim.lsp.omnifunc()|, use |i_CTRL-X_CTRL-O| to trigger
- 'omnifunc' is set to |vim.lsp.completion.omnifunc()|, use |i_CTRL-X_CTRL-O| to trigger
completion.
- 'tagfunc' is set to |vim.lsp.tagfunc()|. This enables features like
go-to-definition, |:tjump|, and keymaps like |CTRL-]|, |CTRL-W_]|,
Expand Down Expand Up @@ -125,7 +125,7 @@ FAQ *lsp-faq*

- Q: Why isn't completion working?
- A: In the buffer where you want to use LSP, check that 'omnifunc' is set to
"v:lua.vim.lsp.omnifunc": `:verbose set omnifunc?`
"v:lua.vim.lsp.completion.omnifunc": `:verbose set omnifunc?`
- Some other plugin may be overriding the option. To avoid that you could
set the option in an |after-directory| ftplugin, e.g.
"after/ftplugin/python.vim".
Expand Down Expand Up @@ -514,10 +514,10 @@ LspAttach *LspAttach*
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.server_capabilities.completionProvider then
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
if client.supports_method("textDocument/completion") then
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.completion.omnifunc"
end
if client.server_capabilities.definitionProvider then
if client.supports_method("textDocument/definition") then
vim.bo[bufnr].tagfunc = "v:lua.vim.lsp.tagfunc"
end
end,
Expand Down Expand Up @@ -801,23 +801,6 @@ get_log_path() *vim.lsp.get_log_path()*
Return: ~
(`string`) path to log file

omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
Implements 'omnifunc' compatible LSP completion.

Parameters: ~
{findstart} (`integer`) 0 or 1, decides behavior
{base} (`integer`) findstart=0, text to match against

Return: ~
(`integer|table`) Decided by {findstart}:
• findstart=0: column where the completion starts, or -2 or -3
• findstart=1: list of matches (actually just calls |complete()|)

See also: ~
|complete-functions|
|complete-items|
|CompleteDone|

set_log_level({level}) *vim.lsp.set_log_level()*
Sets the global log level for LSP logging.

Expand Down
9 changes: 5 additions & 4 deletions runtime/lua/vim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function lsp._set_defaults(client, bufnr)
if
client.supports_method(ms.textDocument_completion) and is_empty_or_default(bufnr, 'omnifunc')
then
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.completion.omnifunc'
end
if
client.supports_method(ms.textDocument_rangeFormatting)
Expand Down Expand Up @@ -371,7 +371,7 @@ local function reset_defaults(bufnr)
if vim.bo[bufnr].tagfunc == 'v:lua.vim.lsp.tagfunc' then
vim.bo[bufnr].tagfunc = nil
end
if vim.bo[bufnr].omnifunc == 'v:lua.vim.lsp.omnifunc' then
if vim.bo[bufnr].omnifunc == 'v:lua.vim.lsp.completion.omnifunc' then
vim.bo[bufnr].omnifunc = nil
end
if vim.bo[bufnr].formatexpr == 'v:lua.vim.lsp.formatexpr()' then
Expand Down Expand Up @@ -1001,9 +1001,10 @@ end
---@return integer|table Decided by {findstart}:
--- - findstart=0: column where the completion starts, or -2 or -3
--- - findstart=1: list of matches (actually just calls |complete()|)
---@deprecated
function lsp.omnifunc(findstart, base)
log.debug('omnifunc.findstart', { findstart = findstart, base = base })
return vim.lsp._completion.omnifunc(findstart, base)
vim.deprecate('vim.lsp.omnifunc', 'vim.lsp.completion.omnifunc', '0.12')
return vim.lsp.completion.omnifunc(findstart, base)
end

--- @class vim.lsp.formatexpr.Opts
Expand Down
4 changes: 2 additions & 2 deletions test/functional/plugin/lsp_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('LSP', function()
on_handler = function(_, _, ctx)
if ctx.method == 'test' then
eq('v:lua.vim.lsp.tagfunc', get_buf_option('tagfunc'))
eq('v:lua.vim.lsp.omnifunc', get_buf_option('omnifunc'))
eq('v:lua.vim.lsp.completion.omnifunc', get_buf_option('omnifunc'))
eq('v:lua.vim.lsp.formatexpr()', get_buf_option('formatexpr'))
eq('', get_buf_option('keywordprg'))
eq(
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('LSP', function()
on_handler = function(_, _, ctx)
if ctx.method == 'test' then
eq('v:lua.vim.lsp.tagfunc', get_buf_option('tagfunc', 'BUFFER_1'))
eq('v:lua.vim.lsp.omnifunc', get_buf_option('omnifunc', 'BUFFER_2'))
eq('v:lua.vim.lsp.completion.omnifunc', get_buf_option('omnifunc', 'BUFFER_2'))
eq('v:lua.vim.lsp.formatexpr()', get_buf_option('formatexpr', 'BUFFER_2'))
client.stop()
end
Expand Down

0 comments on commit 8730bec

Please sign in to comment.