summaryrefslogtreecommitdiff
path: root/config/nvim
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-10-12 16:33:58 +0100
committerIgor Soarez <igor@soarez.org>2026-10-12 16:33:58 +0100
commit20b4e6a4f89776d1d0250d95cce341aa77d03da2 (patch)
tree6222695f2a3669fba75be2035818c2655d10cebe /config/nvim
parentb2246e1c3ac8419f3b1c84d557df8e926d451af2 (diff)
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.
Diffstat (limited to 'config/nvim')
-rw-r--r--config/nvim/lua/plugins/lsp.lua17
1 files changed, 17 insertions, 0 deletions
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 = {