-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: ensure rustfmt
runs when configured with ./
#15600
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
fix: ensure rustfmt
runs when configured with ./
#15600
Conversation
@RalfJung Sorry for the delay: my initial, simple fix didn't work for simply specifying something like |
let roots = snap | ||
.workspaces | ||
.iter() | ||
.flat_map(|ws| ws.workspace_definition_path()) | ||
.collect::<Vec<&AbsPath>>(); | ||
|
||
let abs: Option<AbsPathBuf> = roots.into_iter().find_map(|base| { | ||
let abs = base.join(rest); | ||
std::fs::metadata(&abs).ok().map(|_| abs) | ||
}); |
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.
I'm not a fan of this approach, but I can't find a better way to determine what workspace a TextDocument
is a part of.
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.
Take a look at CargoTargetSpec::for_file
, that function has to solve the same problem of relating a file to its workspace(s)
I'm afraid I won't be able to try this, I don't have the setup to build RA myself. Why isn't this as simple as this? let command = self.current_dir().unwrap().join(command); Before #15564, |
|
||
// to support rustc's suggested, default configuration | ||
let mut cmd = match components.next() { | ||
Some(std::path::Component::CurDir) => { |
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.
This should probably work with build/host/rustfmt
as well; special-casing the leading ./
sounds very fragile.
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.
Ye, we can just Path::join the rustfmt path onto the base here. If the path is absolute it'll replace the base, otherwise it"ll append which is exactly the semantics we want to have here.
This should already be working for vscode fwiw, we should probably have the default vscode settings in rust-lang/rust make use of these now that you mention that. And ralf brought up a good point here, should relative paths be relative to the servers working dir, or relative to the workspace root. I think workspace does make more sense though, as the working dir of the server could be anywhere in theory. |
Appreciate the feedback, y'all.
I'm going make to the path relative to the workspace root because I've seen the server be in weird spots. |
Sorry for the delay in responding/further elaborating, folks. Had a muscle spasm in my neck earlier and it's left me a little incapacitated. I'm substantially better now, though. I'll address the comments in order and expand on details where I should've expanded earlier.
Prior to #15564,
I bring up these complications not to filibuster a solution, but rather, outline my thoughts, which are not settled. I'd like to fix this before Monday. I'd personally prefer to avoid the solution that entails
Anyways, I can do any of the above options, just let me know what you prefer. Footnotes
|
Ah, that's fair. My goal was to bring the behavior back to what it was before #15564, but I assume PATH-discovered commands worked then. Sadly it doesn't seem like However, applying shell logic, what should work is:
I appreciate that the current working directory (of the server!) is arbitrary and might not match user intuition, but it matches the behavior before #15564, and the primary priority right now should be to fix the regression. Getting a proper idea of which path to base this on can wait, IMO. |
Taking a look at this in a bit, but setting the path to |
Oh, that already works in currently released RA? I can try that.
|
Yes that seems to work. :) I filed rust-lang/rust#115836 to update the docs. Would be great to have this documented in the setting's doc string. |
Well, technically speaking this is a VSCode feature that we re-implemented in the extension for a very few selected ones, https://code.visualstudio.com/docs/editor/variables-reference |
Huh that is odd, miri is a member of the main workspace so that should work here just fine?
That sounds like a good idea to me (replacing working directory with workspace root). |
Will take that approach, then! |
Whoops, sorry: I thought I had pushed this a while ago, but I updated this PR according to feedback. It turns out that I was using |
@bors r+ |
…r=Veykril fix: ensure `rustfmt` runs when configured with `./` (Hopefully) resolves #15595. This change kinda approaches canonicalization—which I am not a fan of—but only in service of making `./`-configured commands run correctly. Longer-term, I feel like this code should be removed once `rustfmt` supports recursive searches of configuration files or interpolation of values like `${workspace_folder}` lands in rust-analyzer. ## Testing I cloned `rustc`, setup rust-analyzer as suggested in the [`rustc` dev guide](https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc), saved and formatted files in `src/tools/miri` and `compiler`, and saw `rustfmt` (seemingly) correctly.
💔 Test failed - checks-actions |
5522357
to
b3ebc9a
Compare
@bors r+ |
☀️ Test successful - checks-actions |
(Hopefully) resolves #15595. This change kinda approaches canonicalization—which I am not a fan of—but only in service of making
./
-configured commands run correctly.Longer-term, I feel like this code should be removed once
rustfmt
supports recursive searches of configuration files or interpolation of values like${workspace_folder}
lands in rust-analyzer.Testing
I cloned
rustc
, setup rust-analyzer as suggested in therustc
dev guide, saved and formatted files insrc/tools/miri
andcompiler
, and sawrustfmt
(seemingly) correctly.