intellij-rust / intellij-rust

Rust plugin for the IntelliJ Platform
https://intellij-rust.github.io
MIT License
4.53k stars 380 forks source link

rust codes format result is not equal cargo fmt #10752

Open Sherlock-Holo opened 1 year ago

Sherlock-Holo commented 1 year ago

Environment

Problem description

my projects is formated by cargo fmt

when update the Clion to 2023.2 and update the intellij-rust, when I press Ctrl+Alt+L, I found there is a different: image image

the intellij-rust format result is not equal cargo fmt image

I already enable this image

Steps to reproduce

Sherlock-Holo commented 1 year ago

image oh... it seems when enable

Use rustfmt instead of the built-in formatter

the Ctrl+Alt+L doesn't work anymore, in previous version, these a lot of blank lines will be removed

Maksim20023 commented 1 year ago

I investigated and found that described behavior may occur when the option "optimize import" in the "Reformat File" menu is active. It happens because this option also impacts the "Reformate Code" function. Interestingly, when this option is active, blank lines don't remove. And if I uncheck the option "optimize import" in "Reformat File" and run "Reformate Code", imports don't change lines, and blank lines are removed. Could you please, check this option on your side?

Sherlock-Holo commented 1 year ago

I tried disable the optimize import, the blank lines are removed, but the unused imports still exists and intellij-rust just move them to the correct position(when they are used, the position which cargo fmt may choose)

after re-enable the optimize import, the unused import are removed, but blank lines still exists

Sherlock-Holo commented 1 year ago

in previous version intellij-rust, when enable optimize import and the Use rustfmt instead of the built-in formatter, the Ctrl+Alt+L will format the codes like just run cargo fmt directly

Maksim20023 commented 1 year ago

Thank you for providing additional information. The cause of this behavior is that, for some unclear reasons, "rustfmt" doesn't function despite the "Use rustfmt instead of the built-in formatter" option being activated. I forwarded the issue description to our developer team to investigate the root cause of the issue. When we have any new information about it, we will add a reply to this ticket.

rzmahmood commented 1 month ago

I had this issue on RustRover. I resolved it by turning off Rearrange Code