diff options
| author | Ian Liu Rodrigues <ian.liu88@gmail.com> | 2023-03-23 02:49:52 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-23 13:49:52 +0800 |
| commit | b7a1a1ffd96eb89c937ee63e00a20096c73e0035 (patch) | |
| tree | 86ff676417957d7824ad1348623d770c0744e3a5 | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.tar nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.tar.gz nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.tar.bz2 nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.tar.lz nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.tar.xz nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.tar.zst nvim-lspconfig-b7a1a1ffd96eb89c937ee63e00a20096c73e0035.zip | |
feat: add PyrightSetPythonPath command to pyright config (#2519)
* feat: add PyrightSetPythonPath command to pyright config
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.
* docs: update server_configurations.md
skip-checks: true
---------
Co-authored-by: Ian Liu Rodrigues <il@moray.ai>
Co-authored-by: github-actions <github-actions@github.com>
| -rw-r--r-- | doc/server_configurations.md | 1 | ||||
| -rw-r--r-- | doc/server_configurations.txt | 1 | ||||
| -rw-r--r-- | lua/lspconfig/server_configurations/pyright.lua | 17 |
3 files changed, 19 insertions, 0 deletions
diff --git a/doc/server_configurations.md b/doc/server_configurations.md index 40355a64..c9f8dfe6 100644 --- a/doc/server_configurations.md +++ b/doc/server_configurations.md @@ -6230,6 +6230,7 @@ require'lspconfig'.pyright.setup{} ``` **Commands:** - PyrightOrganizeImports: Organize Imports +- PyrightSetPythonPath: Reconfigure pyright with the provided python path **Default values:** - `cmd` : diff --git a/doc/server_configurations.txt b/doc/server_configurations.txt index 40355a64..c9f8dfe6 100644 --- a/doc/server_configurations.txt +++ b/doc/server_configurations.txt @@ -6230,6 +6230,7 @@ require'lspconfig'.pyright.setup{} ``` **Commands:** - PyrightOrganizeImports: Organize Imports +- PyrightSetPythonPath: Reconfigure pyright with the provided python path **Default values:** - `cmd` : diff --git a/lua/lspconfig/server_configurations/pyright.lua b/lua/lspconfig/server_configurations/pyright.lua index a198477f..1bd3dbb6 100644 --- a/lua/lspconfig/server_configurations/pyright.lua +++ b/lua/lspconfig/server_configurations/pyright.lua @@ -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, @@ -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 = [[ |
