all repos — dot @ 20b4e6a4f89776d1d0250d95cce341aa77d03da2

Shell, editor and terminal configuration, and the tools that go with them

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.
Igor Soarez igor@soarez.org
Mon, 12 Oct 2026 16:33:58 +0100
commit

20b4e6a4f89776d1d0250d95cce341aa77d03da2

parent

b2246e1c3ac8419f3b1c84d557df8e926d451af2

1 files changed, 17 insertions(+), 0 deletions(-)

jump to
M config/nvim/lua/plugins/lsp.lua → config/nvim/lua/plugins/lsp.lua

@@ -87,7 +87,24 @@ },

}) -- 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 = {