xdev-software / intellij-plugin-save-actions

Supports configurable, Eclipse like, save actions, including "organize imports", "reformat code" and "rearrange code"
https://plugins.jetbrains.com/plugin/22113
Apache License 2.0
43 stars 3 forks source link

Wrong order on applying actions, Reformat actions should be the last action #90

Closed MrDolch closed 7 months ago

MrDolch commented 7 months ago

I use the Save-Action-X plugin to force the reformatting of my code immediately after editing. I also use the Java Inspection and Quick Fix options to automatically add final to parameters and variables.

The problem is that the Java Inspection and Quick Fix-actions change the length of the lines, but the reformatting depends on the line lengths. Therefore, I have to execute the save actions twice to get the final result.

The solution would be to always call the reformat action after all other code changing actions.

MrDolch commented 7 months ago

This fixed the issue for me locally:

diff --git a/src/main/java/software/xdev/saveactions/processors/GlobalProcessor.java b/src/main/java/software/xdev/saveactions/processors/GlobalProcessor.java
index c161f7a..a823eaf 100644
--- a/src/main/java/software/xdev/saveactions/processors/GlobalProcessor.java
+++ b/src/main/java/software/xdev/saveactions/processors/GlobalProcessor.java
@@ -87,7 +87,7 @@ public enum GlobalProcessor implements Processor
        @Override
        public int getOrder()
        {
-               return 0;
+               return this.action == Action.reformat || this.action == Action.reformatChangedCode ? 3 : 0;
        }
AB-xdev commented 7 months ago

Thank you for the report, I can confirm the problem.

I think that GlobalProcessor should generally always be executed last.

MrDolch commented 7 months ago

Thank you very much!

AB-xdev commented 7 months ago

No problem :)

The fix is available in Version 1.2.0 which, which is already on the marketplace, however JetBrains needs to review each version. So this will likely take 1-2 days until this shows up.