Skip to content

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

Merged
merged 3 commits into from
May 24, 2023

Conversation

ponyii
Copy link
Contributor

@ponyii ponyii commented May 6, 2023

Fixes #14674

These are ad hoc patches for a number of assists that can produce incorrectly indented code, namely:

  • generate_derive
  • add_missing_impl_members
  • add_missing_default_members

Some general solution is required in future, as the same problem arises in many other assists, e.g.

  • replace_derive_with...
  • generate_default_from_enum...
  • generate_default_from_new
  • generate_delegate_methods
    (the list is incomplete)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2023
@@ -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}"));
Copy link
Contributor Author

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.

@ponyii ponyii changed the title fix: generate_derive no longer breaks indentation [WIP] fix: generate_derive no longer breaks indentation May 6, 2023
@ponyii ponyii changed the title [WIP] fix: generate_derive no longer breaks indentation fix: assists no longer break indentation May 8, 2023
@ponyii ponyii force-pushed the fix/generate_derive_breaks_indentation branch from b075364 to e07d638 Compare May 10, 2023 12:36
@Veykril
Copy link
Member

Veykril commented May 24, 2023

@bors r+

@bors
Copy link
Contributor

bors commented May 24, 2023

📌 Commit 49f1092 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 24, 2023

⌛ Testing commit 49f1092 with merge a512774...

@bors
Copy link
Contributor

bors commented May 24, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing a512774 to master...

@bors bors merged commit a512774 into rust-lang:master May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

generate_derive loses indent
4 participants