Skip to content

Commit d5e5487

Browse files
committed
fix(pyright): pyright.organizeimports command fails
Language server `pyright` does not support command `pyright.organizeimports`. This command may require a client extension.
1 parent 408cf07 commit d5e5487

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.github/ci/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ _check_lsp_cmd_prefix() {
5353

5454
# Enforce client:exec_cmd().
5555
_check_exec_cmd() {
56-
local exclude='eslint'
56+
local exclude='eslint\|pyright\|basedpyright'
5757
if git grep -P 'workspace.executeCommand' -- 'lsp/*.lua' | grep -v "$exclude" ; then
5858
_fail 'Use client:exec_cmd() instead of calling request("workspace/executeCommand") directly. Example: lsp/pyright.lua'
5959
fi

lsp/basedpyright.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ return {
4343
},
4444
on_attach = function(client, bufnr)
4545
vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function()
46-
client:exec_cmd({
46+
local params = {
4747
command = 'basedpyright.organizeimports',
4848
arguments = { vim.uri_from_bufnr(bufnr) },
49-
})
49+
}
50+
51+
-- cannot use client:exec_cmd() as it will fail due to the LSP command not being advertised by the server
52+
client.request('workspace/executeCommand', params, nil, bufnr)
5053
end, {
5154
desc = 'Organize Imports',
5255
})

lsp/pyright.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ return {
4343
},
4444
on_attach = function(client, bufnr)
4545
vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function()
46-
client:exec_cmd({
46+
local params = {
4747
command = 'pyright.organizeimports',
4848
arguments = { vim.uri_from_bufnr(bufnr) },
49-
})
49+
}
50+
51+
-- cannot use client:exec_cmd() as it will fail due to the LSP command not being advertised by the server
52+
client.request('workspace/executeCommand', params, nil, bufnr)
5053
end, {
5154
desc = 'Organize Imports',
5255
})

0 commit comments

Comments
 (0)