-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Respect rustfmt indentation settings #1191
Comments
Yeah, we unfortunately hard-code four space indentation for now. |
This also happens for "Fill match arms". |
Out of curiosity, can https://github.com/udoprog/genco be used to generate the code on behalf of RA? It is reportedly whitespace aware and configurable. |
Probably not, editing code should be agnostic about indentation configuration. I think the proper way to fix this is to remove manual indentation entirely in favor of generic indenter: #4182 |
Just as a note, the fact that this is marked unactionable doesn't mean we don't want to fix it, or that no-one is allowed to work on it. It just means we don't see a direct way of making progress on it, because it depends on another issue. If you care about this and think there is a more simple fix for this, feel free to implement it and make a PR. It just needs to work and be maintainable; it should not make it harder to write assists. |
Hi, any hint where this is hardcoded? and what is causing the problem? |
Every snippet literally contains the precise amount of spaces to insert. Changing the indentation currently requires updating all snippets AFAIK. Fixing this issue will require some way to either replace the fixed indentation of the snippets or be able to write the snippets without fixed indentation I think. |
|
It should probably be read from the editor configuration rather than rustfmt.toml. |
Taking a hint from the above comment, I added my preferred |
This should be passed to rustfmt on the command line with |
While formatting via Items remaining to solve before this can be closed:
Lastly, as tehsunnliu asked, do we know where all of these are hardcoded, such that we can build and evaluate a plan for fixing it? |
I already linked where it is hardcoded. See my comment above and @matklad 's reply - which to be honest I didn't really understand. |
It has not no
In the general case, not really no. The text some assists create aren't really single entities that can be formatted by rustfmt (hence the need for our own syntax formatter #1665) |
Ever since I updated to rustc 1.63.0 yesterday, this doesn't work anymore |
Here is my config in VSCode, edited in "[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.tabSize": 2
},
"rust-analyzer.rustfmt.extraArgs": ["--config", "tab_spaces=2"], My rust version is |
@sslime336 you can configure it just once, but it might annoy people if you ever try to contribute to projects without a |
Don't have such fine-grained control, but Code has an |
You are right. My muscle memory makes me didn't even notice that I've pressed the formatting buttons. Sorry. 😂 Btw, thanks for your reminding :) |
Is anyone working on a solution right now? |
@Timoyoungster there is a sollution. It's to add a
Then if you have the following in your VSC settings file:
It will work for not only you, but for anyone working on your project. |
Thank you, I will try that for now. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Can we please change the title from
to
? I don't think we want more ways to configure things. We just want compliance of Rust tools with... themselves. |
The code in the
if let
block was indented by tabs, but "replace with match" suggestion mistakenly indentsmatch
arms with spaces.The text was updated successfully, but these errors were encountered: