diff options
| author | Michele Sorcinelli <michelesr@users.noreply.github.com> | 2025-08-31 01:50:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-30 17:50:16 -0700 |
| commit | 386231e6b746206147fc62d0243f09904a0a2f1f (patch) | |
| tree | d5ea308c3231eadadcc9e8409e654241e9180d6c | |
| parent | docs: update configs.md (diff) | |
| download | nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.tar nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.tar.gz nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.tar.bz2 nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.tar.lz nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.tar.xz nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.tar.zst nvim-lspconfig-386231e6b746206147fc62d0243f09904a0a2f1f.zip | |
fix(pyright): command :LspPyrightOrganizeImports fails #3971
Problem:
The `pyright.organizeimports` is private, so client:exec_cmd()
fails because it refuses to run commands that are not advertised
as capabilities.
Solution:
Call client.request() to side-step the check in client:exec_cmd().
YOLO
| -rw-r--r-- | .github/ci/lint.sh | 2 | ||||
| -rw-r--r-- | lsp/basedpyright.lua | 9 | ||||
| -rw-r--r-- | lsp/pyright.lua | 9 |
3 files changed, 15 insertions, 5 deletions
diff --git a/.github/ci/lint.sh b/.github/ci/lint.sh index 5b774f92..a6bf8a1e 100644 --- a/.github/ci/lint.sh +++ b/.github/ci/lint.sh @@ -53,7 +53,7 @@ _check_lsp_cmd_prefix() { # Enforce client:exec_cmd(). _check_exec_cmd() { - local exclude='eslint' + local exclude='eslint\|pyright\|basedpyright' if git grep -P 'workspace.executeCommand' -- 'lsp/*.lua' | grep -v "$exclude" ; then _fail 'Use client:exec_cmd() instead of calling request("workspace/executeCommand") directly. Example: lsp/pyright.lua' fi diff --git a/lsp/basedpyright.lua b/lsp/basedpyright.lua index ad3b03b7..e468b94d 100644 --- a/lsp/basedpyright.lua +++ b/lsp/basedpyright.lua @@ -43,10 +43,15 @@ return { }, on_attach = function(client, bufnr) vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() - client:exec_cmd({ + local params = { command = 'basedpyright.organizeimports', arguments = { vim.uri_from_bufnr(bufnr) }, - }) + } + + -- Using client.request() directly because "basedpyright.organizeimports" is private + -- (not advertised via capabilities), which client:exec_cmd() refuses to call. + -- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 + client.request('workspace/executeCommand', params, nil, bufnr) end, { desc = 'Organize Imports', }) diff --git a/lsp/pyright.lua b/lsp/pyright.lua index 2df4a173..1a966304 100644 --- a/lsp/pyright.lua +++ b/lsp/pyright.lua @@ -43,10 +43,15 @@ return { }, on_attach = function(client, bufnr) vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() - client:exec_cmd({ + local params = { command = 'pyright.organizeimports', arguments = { vim.uri_from_bufnr(bufnr) }, - }) + } + + -- Using client.request() directly because "pyright.organizeimports" is private + -- (not advertised via capabilities), which client:exec_cmd() refuses to call. + -- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 + client.request('workspace/executeCommand', params, nil, bufnr) end, { desc = 'Organize Imports', }) |
