mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(lsp): remove deprecated lsp functions (#20421)
This commit is contained in:
parent
afb7efb373
commit
e54541f7f9
@ -1145,59 +1145,6 @@ format({options}) *vim.lsp.buf.format()*
|
||||
Defaults to `nil` in other modes, formatting the full
|
||||
buffer
|
||||
|
||||
formatting({options}) *vim.lsp.buf.formatting()*
|
||||
Formats the current buffer.
|
||||
|
||||
Parameters: ~
|
||||
{options} (table|nil) Can be used to specify FormattingOptions. Some
|
||||
unspecified options will be automatically derived from the
|
||||
current Neovim options.
|
||||
|
||||
See also: ~
|
||||
https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
|
||||
|
||||
*vim.lsp.buf.formatting_seq_sync()*
|
||||
formatting_seq_sync({options}, {timeout_ms}, {order})
|
||||
Formats the current buffer by sequentially requesting formatting from
|
||||
attached clients.
|
||||
|
||||
Useful when multiple clients with formatting capability are attached.
|
||||
|
||||
Since it's synchronous, can be used for running on save, to make sure
|
||||
buffer is formatted prior to being saved. {timeout_ms} is passed on to the
|
||||
|vim.lsp.client| `request_sync` method. Example: >
|
||||
|
||||
vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
|
||||
<
|
||||
|
||||
Parameters: ~
|
||||
{options} (table|nil) `FormattingOptions` entries
|
||||
{timeout_ms} (number|nil) Request timeout
|
||||
{order} (table|nil) List of client names. Formatting is
|
||||
requested from clients in the following order: first all
|
||||
clients that are not in the `order` list, then the
|
||||
remaining clients in the order as they occur in the
|
||||
`order` list.
|
||||
|
||||
*vim.lsp.buf.formatting_sync()*
|
||||
formatting_sync({options}, {timeout_ms})
|
||||
Performs |vim.lsp.buf.formatting()| synchronously.
|
||||
|
||||
Useful for running on save, to make sure buffer is formatted prior to
|
||||
being saved. {timeout_ms} is passed on to |vim.lsp.buf_request_sync()|.
|
||||
Example:
|
||||
>
|
||||
|
||||
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
|
||||
<
|
||||
|
||||
Parameters: ~
|
||||
{options} (table|nil) with valid `FormattingOptions` entries
|
||||
{timeout_ms} (number) Request timeout
|
||||
|
||||
See also: ~
|
||||
|vim.lsp.buf.format()|
|
||||
|
||||
hover() *vim.lsp.buf.hover()*
|
||||
Displays hover information about the symbol under the cursor in a floating
|
||||
window. Calling the function twice will jump into the floating window.
|
||||
@ -1224,32 +1171,6 @@ outgoing_calls() *vim.lsp.buf.outgoing_calls()*
|
||||
|quickfix| window. If the symbol can resolve to multiple items, the user
|
||||
can pick one in the |inputlist()|.
|
||||
|
||||
*vim.lsp.buf.range_code_action()*
|
||||
range_code_action({context}, {start_pos}, {end_pos})
|
||||
Performs |vim.lsp.buf.code_action()| for a given range.
|
||||
|
||||
Parameters: ~
|
||||
{context} (table|nil) `CodeActionContext` of the LSP specification:
|
||||
• diagnostics: (table|nil) LSP`Diagnostic[]` . Inferred from the current position if not provided.
|
||||
• only: (table|nil) List of LSP `CodeActionKind`s used to
|
||||
filter the code actions. Most language servers support
|
||||
values like `refactor` or `quickfix`.
|
||||
{start_pos} ({number, number}, optional) mark-indexed position.
|
||||
Defaults to the start of the last visual selection.
|
||||
{end_pos} ({number, number}, optional) mark-indexed position.
|
||||
Defaults to the end of the last visual selection.
|
||||
|
||||
*vim.lsp.buf.range_formatting()*
|
||||
range_formatting({options}, {start_pos}, {end_pos})
|
||||
Formats a given range.
|
||||
|
||||
Parameters: ~
|
||||
{options} Table with valid `FormattingOptions` entries.
|
||||
{start_pos} ({number, number}, optional) mark-indexed position.
|
||||
Defaults to the start of the last visual selection.
|
||||
{end_pos} ({number, number}, optional) mark-indexed position.
|
||||
Defaults to the end of the last visual selection.
|
||||
|
||||
references({context}, {options}) *vim.lsp.buf.references()*
|
||||
Lists all the references to the symbol under the cursor in the quickfix
|
||||
window.
|
||||
|
@ -118,38 +118,6 @@ function M.completion(context)
|
||||
return request('textDocument/completion', params)
|
||||
end
|
||||
|
||||
---@private
|
||||
--- If there is more than one client that supports the given method,
|
||||
--- asks the user to select one.
|
||||
--
|
||||
---@returns The client that the user selected or nil
|
||||
local function select_client(method, on_choice)
|
||||
validate({
|
||||
on_choice = { on_choice, 'function', false },
|
||||
})
|
||||
local clients = vim.tbl_values(vim.lsp.buf_get_clients())
|
||||
clients = vim.tbl_filter(function(client)
|
||||
return client.supports_method(method)
|
||||
end, clients)
|
||||
-- better UX when choices are always in the same order (between restarts)
|
||||
table.sort(clients, function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
|
||||
if #clients > 1 then
|
||||
vim.ui.select(clients, {
|
||||
prompt = 'Select a language server:',
|
||||
format_item = function(client)
|
||||
return client.name
|
||||
end,
|
||||
}, on_choice)
|
||||
elseif #clients < 1 then
|
||||
on_choice(nil)
|
||||
else
|
||||
on_choice(clients[1])
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
---@return table {start={row, col}, end={row, col}} using (1, 0) indexing
|
||||
local function range_from_selection()
|
||||
@ -283,139 +251,6 @@ function M.format(options)
|
||||
end
|
||||
end
|
||||
|
||||
--- Formats the current buffer.
|
||||
---
|
||||
---@param options (table|nil) Can be used to specify FormattingOptions.
|
||||
--- Some unspecified options will be automatically derived from the current
|
||||
--- Neovim options.
|
||||
--
|
||||
---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
|
||||
function M.formatting(options)
|
||||
vim.notify_once(
|
||||
'vim.lsp.buf.formatting is deprecated. Use vim.lsp.buf.format { async = true } instead',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local params = util.make_formatting_params(options)
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
select_client('textDocument/formatting', function(client)
|
||||
if client == nil then
|
||||
return
|
||||
end
|
||||
|
||||
return client.request('textDocument/formatting', params, nil, bufnr)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Performs |vim.lsp.buf.formatting()| synchronously.
|
||||
---
|
||||
--- Useful for running on save, to make sure buffer is formatted prior to being
|
||||
--- saved. {timeout_ms} is passed on to |vim.lsp.buf_request_sync()|. Example:
|
||||
---
|
||||
--- <pre>
|
||||
--- autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
|
||||
--- </pre>
|
||||
---
|
||||
---@param options table|nil with valid `FormattingOptions` entries
|
||||
---@param timeout_ms (number) Request timeout
|
||||
---@see |vim.lsp.buf.format()|
|
||||
function M.formatting_sync(options, timeout_ms)
|
||||
vim.notify_once(
|
||||
'vim.lsp.buf.formatting_sync is deprecated. Use vim.lsp.buf.format instead',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local params = util.make_formatting_params(options)
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
select_client('textDocument/formatting', function(client)
|
||||
if client == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local result, err = client.request_sync('textDocument/formatting', params, timeout_ms, bufnr)
|
||||
if result and result.result then
|
||||
util.apply_text_edits(result.result, bufnr, client.offset_encoding)
|
||||
elseif err then
|
||||
vim.notify('vim.lsp.buf.formatting_sync: ' .. err, vim.log.levels.WARN)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--- Formats the current buffer by sequentially requesting formatting from attached clients.
|
||||
---
|
||||
--- Useful when multiple clients with formatting capability are attached.
|
||||
---
|
||||
--- Since it's synchronous, can be used for running on save, to make sure buffer is formatted
|
||||
--- prior to being saved. {timeout_ms} is passed on to the |vim.lsp.client| `request_sync` method.
|
||||
--- Example:
|
||||
--- <pre>
|
||||
--- vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
|
||||
--- </pre>
|
||||
---
|
||||
---@param options (table|nil) `FormattingOptions` entries
|
||||
---@param timeout_ms (number|nil) Request timeout
|
||||
---@param order (table|nil) List of client names. Formatting is requested from clients
|
||||
---in the following order: first all clients that are not in the `order` list, then
|
||||
---the remaining clients in the order as they occur in the `order` list.
|
||||
function M.formatting_seq_sync(options, timeout_ms, order)
|
||||
vim.notify_once(
|
||||
'vim.lsp.buf.formatting_seq_sync is deprecated. Use vim.lsp.buf.format instead',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
local clients = vim.tbl_values(vim.lsp.buf_get_clients())
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
|
||||
-- sort the clients according to `order`
|
||||
for _, client_name in pairs(order or {}) do
|
||||
-- if the client exists, move to the end of the list
|
||||
for i, client in pairs(clients) do
|
||||
if client.name == client_name then
|
||||
table.insert(clients, table.remove(clients, i))
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- loop through the clients and make synchronous formatting requests
|
||||
for _, client in pairs(clients) do
|
||||
if vim.tbl_get(client.server_capabilities, 'documentFormattingProvider') then
|
||||
local params = util.make_formatting_params(options)
|
||||
local result, err = client.request_sync(
|
||||
'textDocument/formatting',
|
||||
params,
|
||||
timeout_ms,
|
||||
api.nvim_get_current_buf()
|
||||
)
|
||||
if result and result.result then
|
||||
util.apply_text_edits(result.result, bufnr, client.offset_encoding)
|
||||
elseif err then
|
||||
vim.notify(
|
||||
string.format('vim.lsp.buf.formatting_seq_sync: (%s) %s', client.name, err),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Formats a given range.
|
||||
---
|
||||
---@param options Table with valid `FormattingOptions` entries.
|
||||
---@param start_pos ({number, number}, optional) mark-indexed position.
|
||||
---Defaults to the start of the last visual selection.
|
||||
---@param end_pos ({number, number}, optional) mark-indexed position.
|
||||
---Defaults to the end of the last visual selection.
|
||||
function M.range_formatting(options, start_pos, end_pos)
|
||||
vim.deprecate('vim.lsp.buf.range_formatting', 'vim.lsp.formatexpr or vim.lsp.buf.format', '0.9.0')
|
||||
local params = util.make_given_range_params(start_pos, end_pos)
|
||||
params.options = util.make_formatting_params(options).options
|
||||
select_client('textDocument/rangeFormatting', function(client)
|
||||
if client == nil then
|
||||
return
|
||||
end
|
||||
|
||||
return client.request('textDocument/rangeFormatting', params)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Renames all references to the symbol under the cursor.
|
||||
---
|
||||
---@param new_name string|nil If not provided, the user will be prompted for a new
|
||||
@ -943,34 +778,6 @@ function M.code_action(options)
|
||||
code_action_request(params, options)
|
||||
end
|
||||
|
||||
--- Performs |vim.lsp.buf.code_action()| for a given range.
|
||||
---
|
||||
---
|
||||
---@param context table|nil `CodeActionContext` of the LSP specification:
|
||||
--- - diagnostics: (table|nil)
|
||||
--- LSP `Diagnostic[]`. Inferred from the current
|
||||
--- position if not provided.
|
||||
--- - only: (table|nil)
|
||||
--- List of LSP `CodeActionKind`s used to filter the code actions.
|
||||
--- Most language servers support values like `refactor`
|
||||
--- or `quickfix`.
|
||||
---@param start_pos ({number, number}, optional) mark-indexed position.
|
||||
---Defaults to the start of the last visual selection.
|
||||
---@param end_pos ({number, number}, optional) mark-indexed position.
|
||||
---Defaults to the end of the last visual selection.
|
||||
function M.range_code_action(context, start_pos, end_pos)
|
||||
vim.deprecate('vim.lsp.buf.range_code_action', 'vim.lsp.buf.code_action', '0.9.0')
|
||||
validate({ context = { context, 't', true } })
|
||||
context = context or {}
|
||||
if not context.diagnostics then
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
|
||||
end
|
||||
local params = util.make_given_range_params(start_pos, end_pos)
|
||||
params.context = context
|
||||
code_action_request(params)
|
||||
end
|
||||
|
||||
--- Executes an LSP server command.
|
||||
---
|
||||
---@param command_params table A valid `ExecuteCommandParams` object
|
||||
|
Loading…
Reference in New Issue
Block a user