diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2025-04-21 13:43:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-21 13:43:00 -0700 |
| commit | 44ba712bc3015cce9b599d18f947d85a630e512b (patch) | |
| tree | ae71e900e2c0c8f34bca009c4ec1f3e0d3d21051 /lsp | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.tar nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.tar.gz nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.tar.bz2 nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.tar.lz nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.tar.xz nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.tar.zst nvim-lspconfig-44ba712bc3015cce9b599d18f947d85a630e512b.zip | |
ci(lint): use client:exec_cmd() #3755
Use `client:exec_cmd()` instead of calling
`request("workspace/executeCommand")` directly.
Diffstat (limited to 'lsp')
| -rw-r--r-- | lsp/basedpyright.lua | 24 | ||||
| -rw-r--r-- | lsp/denols.lua | 28 | ||||
| -rw-r--r-- | lsp/pyright.lua | 26 | ||||
| -rw-r--r-- | lsp/texlab.lua | 10 | ||||
| -rw-r--r-- | lsp/zk.lua | 18 |
5 files changed, 39 insertions, 67 deletions
diff --git a/lsp/basedpyright.lua b/lsp/basedpyright.lua index f78bbd21..8872ea14 100644 --- a/lsp/basedpyright.lua +++ b/lsp/basedpyright.lua @@ -4,21 +4,6 @@ --- --- `basedpyright`, a static type checker and language server for python -local function organize_imports() - local params = { - command = 'basedpyright.organizeimports', - arguments = { vim.uri_from_bufnr(0) }, - } - - local clients = vim.lsp.get_clients { - bufnr = vim.api.nvim_get_current_buf(), - name = 'basedpyright', - } - for _, client in ipairs(clients) do - client.request('workspace/executeCommand', params, nil, 0) - end -end - local function set_python_path(path) local clients = vim.lsp.get_clients { bufnr = vim.api.nvim_get_current_buf(), @@ -55,8 +40,13 @@ return { }, }, }, - on_attach = function() - vim.api.nvim_buf_create_user_command(0, 'LspPyrightOrganizeImports', organize_imports, { + on_attach = function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() + client:exec_cmd({ + command = 'basedpyright.organizeimports', + arguments = { vim.uri_from_bufnr(bufnr) }, + }) + end, { desc = 'Organize Imports', }) diff --git a/lsp/denols.lua b/lsp/denols.lua index 80ff679e..b7a6466a 100644 --- a/lsp/denols.lua +++ b/lsp/denols.lua @@ -15,19 +15,6 @@ local lsp = vim.lsp -local function buf_cache(bufnr, client) - local params = { - command = 'deno.cache', - arguments = { {}, vim.uri_from_bufnr(bufnr) }, - } - client.request('workspace/executeCommand', params, function(err, _result, ctx) - if err then - local uri = ctx.params.arguments[2] - vim.api.nvim_err_writeln('cache command failed for ' .. vim.uri_to_fname(uri)) - end - end, bufnr) -end - local function virtual_text_document_handler(uri, res, client) if not res then return nil @@ -105,12 +92,17 @@ return { ['textDocument/typeDefinition'] = denols_handler, ['textDocument/references'] = denols_handler, }, - on_attach = function() + on_attach = function(client, bufnr) vim.api.nvim_buf_create_user_command(0, 'LspDenolsCache', function() - local clients = vim.lsp.get_clients { bufnr = 0, name = 'denols' } - if #clients > 0 then - buf_cache(0, clients[#clients]) - end + client:exec_cmd({ + command = 'deno.cache', + arguments = { {}, vim.uri_from_bufnr(bufnr) }, + }, { bufnr = bufnr }, function(err, _result, ctx) + if err then + local uri = ctx.params.arguments[2] + vim.api.nvim_err_writeln('cache command failed for ' .. vim.uri_to_fname(uri)) + end + end) end, { desc = 'Cache a module and all of its dependencies.', }) diff --git a/lsp/pyright.lua b/lsp/pyright.lua index 161b8e0e..c44fecfa 100644 --- a/lsp/pyright.lua +++ b/lsp/pyright.lua @@ -4,21 +4,6 @@ --- --- `pyright`, a static type checker and language server for python -local function organize_imports() - local params = { - command = 'pyright.organizeimports', - arguments = { vim.uri_from_bufnr(0) }, - } - - local clients = vim.lsp.get_clients { - bufnr = vim.api.nvim_get_current_buf(), - name = 'pyright', - } - for _, client in ipairs(clients) do - client.request('workspace/executeCommand', params, nil, 0) - end -end - local function set_python_path(path) local clients = vim.lsp.get_clients { bufnr = vim.api.nvim_get_current_buf(), @@ -55,11 +40,16 @@ return { }, }, }, - on_attach = function() - vim.api.nvim_buf_create_user_command(0, 'LspPyrightOrganizeImports', organize_imports, { + on_attach = function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() + client:exec_cmd({ + command = 'pyright.organizeimports', + arguments = { vim.uri_from_bufnr(bufnr) }, + }) + end, { desc = 'Organize Imports', }) - vim.api.nvim_buf_create_user_command(0, 'LspPyrightSetPythonPath', set_python_path, { + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightSetPythonPath', set_python_path, { desc = 'Reconfigure pyright with the provided python path', nargs = 1, complete = 'file', diff --git a/lsp/texlab.lua b/lsp/texlab.lua index 8123d5b7..5636b031 100644 --- a/lsp/texlab.lua +++ b/lsp/texlab.lua @@ -63,12 +63,12 @@ local function buf_cancel_build(client, bufnr) end local function dependency_graph(client) - client.request('workspace/executeCommand', { command = 'texlab.showDependencyGraph' }, function(err, result) + client:exec_cmd({ command = 'texlab.showDependencyGraph' }, { bufnr = 0 }, function(err, result) if err then return vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR) end vim.notify('The dependency graph has been generated:\n' .. result, vim.log.levels.INFO) - end, 0) + end) end local function command_factory(cmd) @@ -102,10 +102,10 @@ end local function buf_find_envs(client, bufnr) local win = vim.api.nvim_get_current_win() - client.request('workspace/executeCommand', { + client:exec_cmd({ command = 'texlab.findEnvironments', arguments = { vim.lsp.util.make_position_params(win, client.offset_encoding) }, - }, function(err, result) + }, { bufnr = bufnr }, function(err, result) if err then return vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR) end @@ -126,7 +126,7 @@ local function buf_find_envs(client, bufnr) border = 'single', title = 'Environments', }) - end, bufnr) + end) end local function buf_change_env(client, bufnr) @@ -16,11 +16,11 @@ return { cmd = { 'zk', 'lsp' }, filetypes = { 'markdown' }, root_markers = { '.zk' }, - on_attach = function() - vim.api.nvim_buf_create_user_command(0, 'LspZkIndex', function() + on_attach = function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspZkIndex', function() vim.lsp.buf.execute_command { command = 'zk.index', - arguments = { vim.api.nvim_buf_get_name(0) }, + arguments = { vim.api.nvim_buf_get_name(bufnr) }, } end, { desc = 'ZkIndex', @@ -30,10 +30,10 @@ return { local bufpath = vim.api.nvim_buf_get_name(0) local root = find_zk_root(bufpath) - vim.lsp.buf_request(0, 'workspace/executeCommand', { + client:exec_cmd({ command = 'zk.list', arguments = { root, { select = { 'path' } } }, - }, function(_, result, _, _) + }, { bufnr = bufnr }, function(_err, result) if not result then return end @@ -48,14 +48,14 @@ return { desc = 'ZkList', }) - vim.api.nvim_buf_create_user_command(0, 'LspZkNew', function(...) - vim.lsp.buf_request(0, 'workspace/executeCommand', { + vim.api.nvim_buf_create_user_command(bufnr, 'LspZkNew', function(...) + client:exec_cmd({ command = 'zk.new', arguments = { - vim.api.nvim_buf_get_name(0), + vim.api.nvim_buf_get_name(bufnr), ..., }, - }, function(_, result, _, _) + }, { bufnr = bufnr }, function(_err, result) if not (result and result.path) then return end |
