Skip to content

Commit

Permalink
Add PyrightSetPythonPath command in pyright config
Browse files Browse the repository at this point in the history
The new command accepts a single path for a python executable that will
be used to reconfigure the pyright language server. This is useful to
change which python will be used by pyright without having to activate
the python environment beforehand. The act of finding which python
executable to use isn't handled here.
  • Loading branch information
Ian Liu Rodrigues committed Mar 21, 2023
1 parent 0f94c5f commit d6f154e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lua/lspconfig/server_configurations/pyright.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ local function organize_imports()
vim.lsp.buf.execute_command(params)
end

local function set_python_path(path)
local clients = vim.lsp.get_active_clients {
bufnr = vim.api.nvim_get_current_buf(),
name = 'pyright',
}
for _, client in ipairs(clients) do
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } })
client.notify('workspace/didChangeConfiguration', { settings = nil })
end
end

return {
default_config = {
cmd = cmd,
Expand All @@ -45,6 +56,12 @@ return {
organize_imports,
description = 'Organize Imports',
},
PyrightSetPythonPath = {
set_python_path,
description = 'Reconfigure pyright with the provided python path',
nargs = 1,
complete = 'file',
},
},
docs = {
description = [[
Expand Down

0 comments on commit d6f154e

Please sign in to comment.