Use CWD to resolve settings from ruff.configuration#14352
Merged
dhruvmanila merged 1 commit intomainfrom Nov 15, 2024
Merged
Conversation
Contributor
|
MichaReiser
approved these changes
Nov 15, 2024
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.
Summary
This PR fixes a bug in the Ruff language server where the editor-specified configuration was resolved relative to the configuration directory and not the current working directory.
The existing behavior is confusing given that this config file is specified by the user and is not discovered by Ruff itself. The behavior of resolving this configuration file should be similar to that of the
--configflag on the command-line which uses the current working directory:ruff/crates/ruff/src/resolve.rs
Lines 34 to 48 in 3210f1a
This creates problems where certain configuration options doesn't work because the paths resolved in that case are relative to the configuration directory and not the current working directory in which the editor is expected to be in. For example, the
lint.per-file-ignoresdoesn't work as mentioned in the linked issue along withexclude,extend-exclude, etc.fixes: #14282
Test Plan
Using the following directory tree structure:
where, the
ruff.tomlis:And, the content of
a.py:"""Test"""And, the VS Code settings:
{ "ruff.nativeServer": "on", "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"], // For single-file mode where current working directory is `/` // "ruff.configuration": "/tmp/ruff-repro/.config/ruff.toml", // When a workspace is opened containing this path "ruff.configuration": "./.config/ruff.toml", "ruff.trace.server": "messages", "ruff.logLevel": "trace" }I also tested out just opening the file in single-file mode where the current working directory is
/in VS Code. Here, theruff.configurationneeds to be updated to use absolute path as shown in the above VS Code settings.