From b7a1a1ffd96eb89c937ee63e00a20096c73e0035 Mon Sep 17 00:00:00 2001 From: Ian Liu Rodrigues Date: Thu, 23 Mar 2023 02:49:52 -0300 Subject: 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 Co-authored-by: github-actions --- lua/lspconfig/server_configurations/pyright.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lua') 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 = [[ -- cgit v1.2.3-70-g09d2