mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
feat(lsp): deprecate execute_command with client:exec_cmd
This commit is contained in:

committed by
Lewis Russell

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