Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add PyrightSetPythonPath command to pyright config #2519

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/server_configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6228,6 +6228,7 @@ require'lspconfig'.pyright.setup{}
```
**Commands:**
- PyrightOrganizeImports: Organize Imports
- PyrightSetPythonPath: Reconfigure pyright with the provided python path

**Default values:**
- `cmd` :
Expand Down
1 change: 1 addition & 0 deletions doc/server_configurations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6228,6 +6228,7 @@ require'lspconfig'.pyright.setup{}
```
**Commands:**
- PyrightOrganizeImports: Organize Imports
- PyrightSetPythonPath: Reconfigure pyright with the provided python path

**Default values:**
- `cmd` :
Expand Down
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