mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
feat(lsp): deprecate execute_command with client:exec_cmd
This commit is contained in:
parent
39d79efa1e
commit
7a7747f1e4
@ -45,6 +45,7 @@ TREESITTER
|
||||
|
||||
LSP
|
||||
• *vim.lsp.util.jump_to_location*
|
||||
• *vim.lsp.buf.execute_command* Use |Client:exec_cmd()| instead.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
DEPRECATED IN 0.10 *deprecated-0.10*
|
||||
|
@ -1084,6 +1084,11 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
• {is_stopped} (`fun(): boolean`) Checks whether a client is
|
||||
stopped. Returns: true if the client is fully
|
||||
stopped.
|
||||
• {exec_cmd} (`fun(self: vim.lsp.Client, command: lsp.Command, context: {bufnr?: integer}?, handler: lsp.Handler?)`)
|
||||
Execute a lsp command, either via client
|
||||
command function (if available) or via
|
||||
workspace/executeCommand (if supported by the
|
||||
server)
|
||||
|
||||
*vim.lsp.Client.Progress*
|
||||
Extends: |vim.Ringbuf|
|
||||
@ -1213,6 +1218,15 @@ Lua module: vim.lsp.client *lsp-client*
|
||||
on initialization.
|
||||
|
||||
|
||||
Client:exec_cmd({command}, {context}, {handler}) *Client:exec_cmd()*
|
||||
Execute a lsp command, either via client command function (if available)
|
||||
or via workspace/executeCommand (if supported by the server)
|
||||
|
||||
Parameters: ~
|
||||
• {command} (`lsp.Command`)
|
||||
• {context} (`{bufnr?: integer}?`)
|
||||
• {handler} (`lsp.Handler?`) only called if a server command
|
||||
|
||||
|
||||
==============================================================================
|
||||
Lua module: vim.lsp.buf *lsp-buf*
|
||||
@ -1344,15 +1358,6 @@ document_symbol({opts}) *vim.lsp.buf.document_symbol()*
|
||||
Parameters: ~
|
||||
• {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
|
||||
|
||||
execute_command({command_params}) *vim.lsp.buf.execute_command()*
|
||||
Executes an LSP server command.
|
||||
|
||||
Parameters: ~
|
||||
• {command_params} (`lsp.ExecuteCommandParams`)
|
||||
|
||||
See also: ~
|
||||
• https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
||||
|
||||
format({opts}) *vim.lsp.buf.format()*
|
||||
Formats a buffer using the attached (and optionally filtered) language
|
||||
server clients.
|
||||
|
@ -881,7 +881,8 @@ local function on_code_action_results(results, opts)
|
||||
local a_cmd = action.command
|
||||
if a_cmd then
|
||||
local command = type(a_cmd) == 'table' and a_cmd or action
|
||||
client:_exec_cmd(command, ctx)
|
||||
--- @cast command lsp.Command
|
||||
client:exec_cmd(command, ctx)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1037,12 +1038,14 @@ function M.code_action(opts)
|
||||
end
|
||||
end
|
||||
|
||||
--- @deprecated
|
||||
--- Executes an LSP server command.
|
||||
--- @param command_params lsp.ExecuteCommandParams
|
||||
--- @see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
||||
function M.execute_command(command_params)
|
||||
validate('command', command_params.command, 'string')
|
||||
validate('arguments', command_params.arguments, 'table', true)
|
||||
vim.deprecate('execute_command', 'client:exec_cmd', '0.12')
|
||||
command_params = {
|
||||
command = command_params.command,
|
||||
arguments = command_params.arguments,
|
||||
|
@ -859,10 +859,9 @@ end
|
||||
--- or via workspace/executeCommand (if supported by the server)
|
||||
---
|
||||
--- @param command lsp.Command
|
||||
--- @param context? {bufnr: integer}
|
||||
--- @param context? {bufnr?: integer}
|
||||
--- @param handler? lsp.Handler only called if a server command
|
||||
--- @param on_unsupported? function handler invoked when the command is not supported by the client.
|
||||
function Client:_exec_cmd(command, context, handler, on_unsupported)
|
||||
function Client:exec_cmd(command, context, handler)
|
||||
context = vim.deepcopy(context or {}, true) --[[@as lsp.HandlerContext]]
|
||||
context.bufnr = context.bufnr or api.nvim_get_current_buf()
|
||||
context.client_id = self.id
|
||||
@ -875,25 +874,23 @@ function Client:_exec_cmd(command, context, handler, on_unsupported)
|
||||
|
||||
local command_provider = self.server_capabilities.executeCommandProvider
|
||||
local commands = type(command_provider) == 'table' and command_provider.commands or {}
|
||||
|
||||
if not vim.list_contains(commands, cmdname) then
|
||||
if on_unsupported then
|
||||
on_unsupported()
|
||||
else
|
||||
vim.notify_once(
|
||||
string.format(
|
||||
'Language server `%s` does not support command `%s`. This command may require a client extension.',
|
||||
self.name,
|
||||
cmdname
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
vim.notify_once(
|
||||
string.format(
|
||||
'Language server `%s` does not support command `%s`. This command may require a client extension.',
|
||||
self.name,
|
||||
cmdname
|
||||
),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
-- Not using command directly to exclude extra properties,
|
||||
-- see https://github.com/python-lsp/python-lsp-server/issues/146
|
||||
--- @type lsp.ExecuteCommandParams
|
||||
local params = {
|
||||
command = command.command,
|
||||
command = cmdname,
|
||||
arguments = command.arguments,
|
||||
}
|
||||
self.request(ms.workspace_executeCommand, params, handler, context.bufnr)
|
||||
|
@ -48,7 +48,7 @@ local function execute_lens(lens, bufnr, client_id)
|
||||
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
|
||||
client:_exec_cmd(lens.command, { bufnr = bufnr }, function(...)
|
||||
client:exec_cmd(lens.command, { bufnr = bufnr }, function(...)
|
||||
vim.lsp.handlers[ms.workspace_executeCommand](...)
|
||||
M.refresh()
|
||||
end)
|
||||
|
@ -548,15 +548,7 @@ local function on_complete_done()
|
||||
|
||||
local command = completion_item.command
|
||||
if command then
|
||||
client:_exec_cmd(command, { bufnr = bufnr }, nil, function()
|
||||
vim.lsp.log.warn(
|
||||
string.format(
|
||||
'Language server `%s` does not support command `%s`. This command may require a client extension.',
|
||||
client.name,
|
||||
command.command
|
||||
)
|
||||
)
|
||||
end)
|
||||
client:exec_cmd(command, { bufnr = bufnr })
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user