-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(config): search for config file recursively on --config-path
#7115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rami3l
wants to merge
4
commits into
rust-lang:main
Choose a base branch
from
rami3l:fix/config-path-dirwalk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3e3dc66
test(config): demonstrate `--config-path` searching behavior
rami3l dfcc9f8
refactor(config): generalize `get_toml_path()`
rami3l f675d14
refactor(config): generalize `resolve_project_file()`
rami3l 3f3d54b
fix(config): search for config file recursively on `--config-path`
rami3l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [workspace] | ||
| members = ["inner_lib"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| disable_all_formatting = true |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [package] | ||
| name = "inner_bin" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| fn main() { | ||
| println!("Hello, world!"); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [package] | ||
| name = "inner_lib" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| disable_all_formatting = true |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub fn add(left:u64,right:u64)->u64{left+right} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
.is_dirnot a sufficient check here?View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewhughes934 Originally that had been largely sufficient, but with the new semantics, the path to be passed in through the base dir mode might not exist immediately, and has to be found via recursive search. In this case, a trailing
/makes it clear that we are looking for a directory rather than a TOML file.This should be able to match how rust-analyzer is calling
rustfmt: it is passing the parent directory of the file, which itself is passed in via stdin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain that case more? If someone passes as path that doesn't existing to
--config-pathI would expect it to error out.My primary concern here is that
/is not a path separator on Windows mostly because of Windows weirdness I expect simply checking for\might also not be sufficient hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewhughes934 I totally get your point no, and my apologies for potential confusion. Here is the full background:
Firstly, when rust-analyzer tries to format
dir/file.rs, it wants to pass--config-path=dirto it, and that directory may or may not have the expected.rustfmt.tomlorrustfmt.toml, so a recursive search should be initiated starting from there. However, due to #4660 being unresolved, rust-analyzer has instead used the hack ofcding todirwhen runningrustfmt.From there, I'd agree that
--config-path=dirshould bail out whendirdoesn't exist.Secondly, however, if the user wants to use a different name for the config file, taking the example mentioned in #4660 (comment):
The
file(.rustfmt.unstable.tomlin the above example) is better placed at CWD, but it may totally be at a different place. This time I OTOH don't want--config-path=fileto bail out immediately because I may want to use../../fileetc.The crux of the problem here, it seems to me, is that
--config-pathis overloaded with two meanings and this has made it hard for us to disambiguate, for which some manual intervention must be involved.The trailing
/is, as you said, probably not the best idea for disambiguation.