From 20b4e6a4f89776d1d0250d95cce341aa77d03da2 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Mon, 12 Oct 2026 16:33:58 +0100 Subject: nvim: one pyright client per project, each on its own venv pyright resolves one pythonPath per server instance, so in a monorepo with a venv per service, every file was checked against whichever interpreter the single client found. The root is now the nearest pyproject.toml, falling back to the markers nvim-lspconfig uses, and the client points at the nearest .venv at or above it -- a uv workspace's shared venv covers members without one. The requested version set params.settings in before_init, which the initialize request does not carry, and looked the venv up with vim.fs.find on a name containing slashes, which 0.11 never matches and which searches down the tree rather than up. Setting config.settings there works because each client gets its own copy of the config and keeps that table as client.settings. Checked with the real config and pyright 1.1 on a mock workspace: a service with its own venv, a member using the workspace's, a requirements.txt project with none, and the workspace root each got their own client and interpreter, and each file resolved only the module installed in its own venv. From change request a48b26. --- config/nvim/lua/plugins/lsp.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index 1470177..e87324c 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -87,7 +87,24 @@ local function configure_lsp() -- Setup LSP configurations using vim.lsp.config }) -- Configure pyright (Python language server) + -- One client per project, so each service in a monorepo gets its own + -- interpreter: pyright resolves one pythonPath per server instance. The + -- nearest pyproject.toml wins over the usual markers, and the client uses + -- the nearest .venv at or above that root, so a uv workspace's shared venv + -- still applies to members that have none of their own. vim.lsp.config('pyright', { + root_dir = function(bufnr, on_dir) + on_dir(vim.fs.root(bufnr, { 'pyproject.toml' }) + or vim.fs.root(bufnr, { 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', 'pyrightconfig.json', '.git' })) + end, + -- config is the client's own copy, and client.settings is this table + before_init = function(_, config) + local venv = config.root_dir and vim.fs.root(config.root_dir, '.venv') + local py = venv and venv .. '/.venv/bin/python' + if py and vim.uv.fs_stat(py) then + config.settings.python.pythonPath = py + end + end, settings = { python = { analysis = { -- cgit v1.2.3