-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: assists no longer break indentation #14752
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: assists no longer break indentation #14752
Conversation
@@ -42,7 +42,8 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt | |||
.next(); | |||
match derive_attr { | |||
None => { | |||
builder.insert_snippet(cap, node_start, "#[derive($0)]\n"); | |||
let indent_level = IndentLevel::from_node(nominal.syntax()); | |||
builder.insert_snippet(cap, node_start, format!("#[derive($0)]\n{indent_level}")); |
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.
NB If there's a comment, it will be considered a part of nominal: Adt
, so indent_level
will be the comment's indent. If this comment and the line containing ADT name have different indents, the indent of later will be changed.
Thus it might be better to calculate here the indent of the ADT name. On the other hand, this assist is expected only to preserve correct indentation, not to fix incorrect one.
generate_derive
no longer breaks indentationgenerate_derive
no longer breaks indentation
generate_derive
no longer breaks indentationb075364
to
e07d638
Compare
…dentation no longer
@bors r+ |
☀️ Test successful - checks-actions |
Fixes #14674
These are ad hoc patches for a number of assists that can produce incorrectly indented code, namely:
Some general solution is required in future, as the same problem arises in many other assists, e.g.
(the list is incomplete)