-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Format placeholder code when generating a crate #7656
Comments
I would like to work on this. |
I was waiting for a team member to comment on whether this is something they'd accept. IMO looking for |
The team briefly discussed this, and it should be ok to run rustfmt on the new file (as long as rustfmt is in the path). It should also probably ignore failures to run rustfmt, though that should be rare (maybe print a warning). I wouldn't bother hunting for rustfmt.toml files. |
I wouldn't bother hunting for rustfmt.toml files.
You mean, because rustfmt already does that?
|
Yea, it also embeds some knowledge about rustfmt that wouldn't be necessary (and checking things like home directory locations, etc. makes it complicated). |
Great. I'll try to do this on the weekend.
Edit: sorry for the misshapen replies, haha.
|
Nope, |
This should already be in the latest stable version, right? It's not working for me, so it seems my implementation is not actually doing anything D: Late edit: yep, it's in 1.43 stable. |
@Kinrany This change is in 1.43 which should be released tomorrow. |
Problem
My workspace has a shared
.rustfmt.toml
. I'm usingcargo new
to create crates in the workspace. I'm also using VSCode and RLS.My config file contains
tab_spaces = 2
, butmain.rs
is not initially formatted according to the config file. When opened in VSCode, the code style is inferred to be 4 spaces, not 2. VSCode does not update this parameter after I format the file.This becomes a problem later, when I try to create a function or a block. Typing
{
andEnter
creates two curly brackets and places the cursor on the next line, as usual, but indented by 4 spaces instead of 2.Solution
If there's a
.rustfmt.toml
in the workspace, use the config to format the placeholder code.Alternatively add
cargo new --fmt
, so that this behavior is opt-in.Notes
Workaround: run
cargo fmt
aftercargo new
.I'm willing to work on this feature, though this will be my first time contributing to Cargo :)
The text was updated successfully, but these errors were encountered: