feat(lsp): add per-client commands (#16101)

This commit is contained in:
Michael Lingelbach
2021-11-01 03:14:59 -07:00
committed by GitHub
parent 7ae86c1d4c
commit 519d8deb08
6 changed files with 79 additions and 32 deletions

View File

@@ -31,15 +31,15 @@ local function execute_lens(lens, bufnr, client_id)
local line = lens.range.start.line
api.nvim_buf_clear_namespace(bufnr, namespaces[client_id], line, line + 1)
local client = vim.lsp.get_client_by_id(client_id)
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
local command = lens.command
local fn = vim.lsp.commands[command.command]
local fn = client.commands[command.command] or vim.lsp.commands[command.command]
if fn then
fn(command, { bufnr = bufnr, client_id = client_id })
return
end
-- Need to use the client that returned the lens → must not use buf_request
local client = vim.lsp.get_client_by_id(client_id)
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
local command_provider = client.server_capabilities.executeCommandProvider
local commands = type(command_provider) == 'table' and command_provider.commands or {}
if not vim.tbl_contains(commands, command.command) then