dubreuia / intellij-plugin-save-actions

Supports configurable, Eclipse like, save actions, including "organize imports", "reformat code" and "rearrange code".
MIT License
531 stars 102 forks source link

The option Reformat only changed code(only if VCS configured) is not working. #304

Closed ya5an closed 4 years ago

ya5an commented 4 years ago

The option Reformat only changed code(only if VCS configured) is not working. Reformatted not only changed lines. Sometimes the whole file is reformatted.

$ cat saveactions_settings.xml 
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="SaveActionSettings">
    <option name="actions">
      <set>
        <option value="activate" />
        <option value="reformatChangedCode" />
      </set>
    </option>
  </component>

I use git

What triggered the plugin CTRL+S

Versions PhpStorm 2019.3.3 Build #PS-193.6494.47, built on February 12, 2020 Runtime version: 11.0.5+10-b520.38 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.15.0-88-generic

Plugin version: 2.0.0

BenediktKersjes commented 4 years ago

I have the same problem.

Versions IntelliJ IDEA 2019.3.3 (Ultimate Edition) Build #IU-193.6494.35, built on February 11, 2020 Runtime version: 11.0.5+10-b520.38 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

Plugin version: 2.0.0

dubreuia commented 4 years ago

Hello! Thank you for opening this issue. We used to have a similar problem, see #114. I could never reproduce it. I'm leaving this bug opened, but I can't reproduce. Any help would be nice.

yaeuge commented 4 years ago

I can confirm some weird formatting behavior with this option enabled. I expect only changed lines to be reformatted or at most their immediate neighbors additionally. See the gif for an example of what actually happens

Reformatting VCS-changed code

KenErikson commented 4 years ago

This gif really sums it up. Random indentation changes in rows close to changed code. Often reformats the function right above an added one, if the code there was saved with indentation that doesn't match your specific code style.

dubreuia commented 4 years ago

Hello @yaeuge, thanks a lot for looking into this, I see what the problem is now. Unfortunately, the code that does the reformat isn't in the Save Actions Plugin, it is in JetBrains's source code (you can check where the processor is instantiated here: https://github.com/dubreuia/intellij-plugin-save-actions/blob/master/src/main/java/com/dubreuia/processors/GlobalProcessor.java#L31).

We have 2 choices here: either we open a bug report on Intellij's YouTrack (this issue is probably language based though, so this problem is for Java), or rewrite the ReformatCodeProcessor so that it works better for your use case. PRs welcomed. Thanks

dubreuia commented 4 years ago

Closing as this is a JetBrains processor problem.

Phoenix616 commented 1 year ago

Does anyone know the ticket number of this with JetBrains or which version (if any) fixed this? Getting this on 2021.2.4 (Ultimate) still and don't want to update IntelliJ any further than necessary as to have a chance to not break other plugins/workflows.