[ruff server] Find config for files outside of open workspaces#22570
Open
ZedThree wants to merge 1 commit intoastral-sh:mainfrom
Open
[ruff server] Find config for files outside of open workspaces#22570ZedThree wants to merge 1 commit intoastral-sh:mainfrom
ZedThree wants to merge 1 commit intoastral-sh:mainfrom
Conversation
Fixes astral-sh#17944 There's two different routes we can go down for finding settings for such files: - the file is below an open workspace, so we can add any settings we find to that workspace - the file is not below an open workspace, in which case we can't cache them Given this filesystem layout: ``` . ├── dir_0 │ ├── ruff.toml │ └── test_0.py └── dir_1 ├── ruff.toml └── test_1.py ``` This fixes: - cwd at top-level, opening `dir_0/test_0.py` - cwd at top-level, opening `dir_0/test_0.py`, then `../dir_1/test_1.py` in same session - cwd in `dir_0`, opening `../dir_1/test_1.py` - cwd in `dir_0`, opening `test_0.py` first, then `../dir_1/test_1.py` in same session without negatively affecting non-default workspaces (such as opening the folder in VS Code or `lsp-mode` in Emacs). The main downside to this approach is the lack of workspace for files in `dir_1` -- we can't share already parsed settings. --- This doesn't work for the situation where we're opening a file in a nested directory below the default workspace, where we _do_ have a config file: ``` . ├── subdir │ ├── ruff.toml │ └── test_1.py ├── ruff.toml └── test_0.py ``` Opening `test_0.py` first (in single file mode), and then opening `subdir/test_1.py` still uses the settings from `./ruff.toml` instead of `subdir/ruff.toml`
|
Member
|
(I've this on my TODO, I'll look at this later today after a meeting.) |
Member
|
Thank you for this PR! The setting resolution is a little bit complicated for the Ruff language server. I think it would be very useful (and would also help me review this faster) if you can link the specific changes to the directory structure which it tries to solve. For example, which directory structure is |
Contributor
Author
|
Previously,
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17944
There's two different routes we can go down for finding settings for such files:
Given this filesystem layout:
This fixes:
dir_0/test_0.pydir_0/test_0.py, then../dir_1/test_1.pyin same sessiondir_0, opening../dir_1/test_1.pydir_0, openingtest_0.pyfirst, then../dir_1/test_1.pyin same sessionwithout negatively affecting non-default workspaces (such as opening the folder in VS Code or
lsp-modein Emacs).The main downside to this approach is the lack of workspace for files in
dir_1-- we can't share already parsed settings.This doesn't work for the situation where we're opening a file in a nested directory below the default workspace, where we do have a config file:
Opening
test_0.pyfirst (in single file mode), and then openingsubdir/test_1.pystill uses the settings from./ruff.tomlinstead ofsubdir/ruff.tomlTest Plan
Tested using the files described in this comment
I noticed that ty has e2e testing of its lsp server, but this hasn't been implemented for ruff yet. I think this would need something like that to test automatically