From 8de923287e5005bcbacff8cbdebe1aa9aadc6939 Mon Sep 17 00:00:00 2001 From: Trevor Hauter Date: Thu, 30 Oct 2025 20:04:48 -0400 Subject: fix(pyright): prioritize "pyrightconfig.json" root marker #4171 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem**: When working in a python monorepo with a base `pyproject.toml`, and `pyrightconfig.json` files that extend this base configuration in subdirectories, `pyright` will not recognize these `pyrightconfig.json` and identify these subdirectories (project1 | project2) as root directories because `pyproject.toml` takes precedence. ```sh # Example structure monorepo ├── project1 │   ├── pyrightconfig.json │   └── src │   └── main.py ├── project2 │   ├── pyrightconfig.json │   └── src │   └── main.py └── pyproject.toml ``` From the pyright docs [1] > A “pyrightconfig.json” file always takes precedent over “pyproject.toml” if both are present **Solution**: Update the order of the `root_markers` to prefer `pyrightconfig.json` so priority is in line with pyrights documentation. **Testing**: When creating a simple monorepo structure with the following command ```sh mkdir monorepo && touch monorepo/pyproject.toml && mkdir monorepo/project1 && touch monorepo/project1/pyrightconfig.json && mkdir monorepo/project1/src && touch monorepo/project1/src/main.py && cp -r monorepo/project1 monorepo/project2 ``` You should be able to open one of the subdirectories `nvim monorepo/project1/src/main.py` and check your LSP root dir with `:LspInfo`, and it should be attached to the subdirectory. 1. https://github.com/microsoft/pyright/blob/main/docs/configuration.md#pyright-configuration --- lsp/basedpyright.lua | 2 +- lsp/pyright.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lsp') diff --git a/lsp/basedpyright.lua b/lsp/basedpyright.lua index 5f54c3d2..0dcaaa3b 100644 --- a/lsp/basedpyright.lua +++ b/lsp/basedpyright.lua @@ -25,12 +25,12 @@ return { cmd = { 'basedpyright-langserver', '--stdio' }, filetypes = { 'python' }, root_markers = { + 'pyrightconfig.json', 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', - 'pyrightconfig.json', '.git', }, settings = { diff --git a/lsp/pyright.lua b/lsp/pyright.lua index edc802e2..b67afffd 100644 --- a/lsp/pyright.lua +++ b/lsp/pyright.lua @@ -25,12 +25,12 @@ return { cmd = { 'pyright-langserver', '--stdio' }, filetypes = { 'python' }, root_markers = { + 'pyrightconfig.json', 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', - 'pyrightconfig.json', '.git', }, settings = { -- cgit v1.2.3-70-g09d2