Coder Social home page Coder Social logo

dubreuia / intellij-plugin-save-actions Goto Github PK

View Code? Open in Web Editor NEW
531.0 20.0 102.0 1.52 MB

Supports configurable, Eclipse like, save actions, including "organize imports", "reformat code" and "rearrange code".

License: MIT License

Java 96.87% Shell 3.13%
intellij java eclipse pycharm phpstorm webstorm jetbrains clion androidstudio

intellij-plugin-save-actions's Introduction

⚠️ This project has been archived and is looking for a maintainer ⚠️

Save Actions Plugin

JetBrains Plugin JetBrains Supported Travis CI Build Status AppVeyor Build Status Codecov Code Coverage

Supports configurable, Eclipse like, save actions, including "optimize imports", "reformat code", "rearrange code", "compile file" and some quick fixes like "add / remove 'this' qualifier", etc. The plugin executes the configured actions when the file is synchronised (or saved) on disk.

Using the save actions plugin makes your code cleaner and more uniform across your code base by enforcing your code style and code rules every time you save. The settings file (see files location) can be shared in your development team so that every developer has the same configuration.

The code style applied by the save actions plugin is the one configured your settings at "File > Settings > Editor > Code Style". For some languages, custom formatter (Dartfmt, Prettier, etc.) may also be triggered by the save actions plugin. See the Editor Actions configuration for more information.

Thank you to JetBrains for supporting the Save Actions plugin: they provide an open-source license, which is necessary to build, test and deploy this plugin. Check out their products at https://www.jetbrains.com.

Save Actions Plugin icon light

Content

Features

All JetBrains products

  • Optimize imports
  • Run on file save, shortcut, batch (or a combination)
  • Run on multiple files by choosing a scope
  • Reformat code (whole file or only changed text)
  • Rearrange code (reorder methods, fields, etc.)
  • Include / exclude files with regex support
  • Works on any file type (Java, Python, XML, etc.)
  • Launch any editor action using "quick lists"
  • Uses a settings file per project you can commit (see Files location)
  • Available keymaps and actions for activation (see Keymap and actions)

Save actions plugin settings page

Java IDE products

Works in JetBrains IDE with Java support, like Intellij IDEA and AndroidStudio.

  • Compile project after save (if compiling is available)
  • Reload debugger after save (if compiling is available)
  • Eclipse configuration file .epf support (see Eclipse support)
  • Automatically fix Java inspections (see Java quick fixes)

Save actions plugin settings page for Java

Installation

IDE (recommended)

Install it from your IDE (Intellij IDEA, PyCharm, etc.):

  • "File > Settings > Plugins > Browse repositories... > Search 'Save Actions' > Category 'Code tools'"

JetBrains plugin repository

All versions of the plugin are available from the JetBrains plugin repository. You can download the jar and add it to your IDE (you won't get updates thought):

  • "File > Settings > Plugins > Install plugin from disk..."

Usage

The plugin can trigger automatically or manually on IDE actions (standard actions) or plugin actions. Most actions needs to be enabled individually (see activation).

IDE actions

The plugin will trigger automatically on any of these IDE actions (needs to be activated with "Activate save actions on file save" in activation)):

  • Frame deactivation, which is when the editor loses focus, configured in "File > Settings > Appearance & Behavior > System Settings > Save files on frame deactivation" .
  • Application idle, which is when the IDE isn't used for a period of time, configured in "File > Settings > Appearance & Behavior > System Settings > Save files automatically if application is idle for x sec".
  • Save All, which is bound by default to "CTRL + S". Some IDE might use "CTRL + S" for the single Save Document action, on which the plugin will NOT trigger. This is by design, see issue #222.

Plugin actions

The plugin actions are grouped under the menu "Code > Save Actions". You can associate a keymap to any action in "Settings > Keymap > Search 'save actions'".

  • Enable Save Actions (default: not binded) will activate or deactivate the plugin by changing the configuration.
  • Execute Save Actions on shortcut (default: "CTRL + SHIFT + S") will trigger the plugin manually (needs to be activated with "Activate save actions on shortcut" in activation).
  • Execute Save Actions on multiple files (default: not binded) will show a popup to select the files (or a scope) on which to trigger the plugin (needs to be activated with "Activate save actions on batch" in activation).

Save Actions Plugin Action menu

Configuration

The configurations are located in "File > Settings > Other Settings > Save Actions".

Activation

You can quickly toggle the plugin activation by using the "Enable Save Action" action. Use "CTRL + SHIFT + A" then search for it. It will also show if it is currently activated or not.

Name Description
Activate save actions on file save Enable / disable the plugin on file save. Before saving each file, it will perform the configured actions below
Activate save actions on shortcut Enable / disable the plugin on shortcut, by default "CTRL + SHIFT + S" (configured in "File > Keymaps > Main menu > Code > Save Actions")
Activate save actions on batch Enable / disable the plugin on batch, by using "Code > Save Actions > Execute on multiple files"
No action if compile errors Enable / disable no action if there are compile errors. Applied to each file individually

Global

Name Description
Optimize imports Enable / disable import organization (configured in "File > Settings > Code Style > Java > Imports")
Reformat file Enable / disable formatting (configured in "File > Settings > Code Style"). See "Reformat only changed code" for more options
Reformat only changed lines Enable / disable formatting for only changed lines, which will work only if a VCS is configured
Rearrange fields and methods Enable / disable re-ordering of fields and methods (configured in "File > Settings > Code Style > Java > Arrangement")

Build

Name Description
[experimental] Compile file Enable / disable compiling of the modified file. The compiler might compile other files as well. Warning: this feature is experimental, please post feedback in the github issues
[experimental] Reload file Enable / disable reloading of the files in the running debugger, meaning the files will get compiled first. The compiler might compile other files as well. Warning: this feature is experimental, please post feedback in the github issues
[experimental] Execute action Enable / disable executing of an action using quick lists (using quick lists at "File > Settings > Appearance & Behavior > Quick Lists"). See Editor Actions for more information Warning: this feature is experimental, please post feedback in the github issues

Editor Actions

Some languages requires specific actions, such as Dartfmt or Prettier:

  • For Dart developers, enable "Use the dartfmt tool when formatting the whole file" option in "File > Settings > Editor > Code Style > Dart > Dartfmt".
  • For Prettier (https://prettier.io/) users, read below.

Using the "Execute action" configuration, the plugin can launch arbitrary editor actions. While not all actions will work, it can be used to launch external tools, specific runs, etc. This feature is experimental, you can post your feedback on issue #118.

The actions are implemented in the form of "quick lists", an IDE function that is used to define a list of actions that can be then executed. Quick lists can be configured at "File > Settings > Appearance & Behavior > Quick Lists", and once configured, one can be selected and used in the plugin, using the "Execution action" configuration drop down list.

File

Name Description
File path inclusions Add / remove file path inclusions (by default, everything included). The Java regular expressions match the whole file name from the project root. Include only Java files: .*\.java.
File path exclusions Add / remove file path exclusions to ignore files (overrides inclusions). The Java regular expressions match the whole file name from the project root. Exclude 'Main.java' only in root folder: Main\.java. Exclude file 'Foo.java' only in folder 'src': src/Foo\.java. Exclude all xml files in any folder: .*/.*\.xml
Use external Eclipse configuration Add external configuration file ".epf" to read settings from. This will update the current settings and use only the ".epf" file content. Use "reset" button to remove

Java fixes

If a quick fix adds something that is removed by another quick fix, the removal wins.

Name Description
Add final modifier to field The field private int field = 0 becomes private final int field = 0
Add final modifier to local variable or parameter The local variable int variable = 0 becomes final int variable = 0
Add final modifier to local variable or parameter except if implicit The local variable int variable = 0 becomes final int variable = 0, but not if it is implicit like in try with resources try (Resource r = new Resource())
Add static modifier to methods The method private void method() becomes private static void method() if the content does not references instance fields
Add this to field access The access to instance field field = 0 becomes this.field = 0
Add this to method access The access to instance method method() becomes this.method()
Add class qualifier to static member access The access to class field FIELD = 0 becomes Class.FIELD for a class named Class. Exclusive with "Add class qualifier to static member access outside declaring class only".
Add class qualifier to static member access outside declaring class only The access to class field FIELD = 0 becomes Class.FIELD for a class named class, but only if the static member is outside declaring class. Exclusive with "Add class qualifier to static member access".
Add missing @Override annotations The method void method() becomes @Override void method() if it overrides a method from the parent class
Add blocks to if/while/for statements The statement if (true) return false becomes if (true) { return false; } (a block), also working for for and while statements
Add missing serialVersionUID field for Serializable classes The class class Class implements Serializable will get a new field private static final long serialVersionUID with generated serial version uid
Remove unnecessary this to field and method The access to instance field this.field = 0 becomes field = 0, also working for methods
Remove final from private method The method private final void method() becomes private void method()
Remove unnecessary final to local variable or parameter The local variable int final variable = 0 becomes int variable = 0
Remove explicit generic type for diamond The list creation List<String> list = new ArrayList<String>() becomes List<String> list = new ArrayList<>()
Remove unused suppress warning annotation The annotation @SuppressWarning will be removed if it is unused (warning: "unchecked" doesn't work properly see #87)
Remove unnecessary semicolon The statement int variable = 0;; becomes int variable = 0;
Remove blocks from if/while/for statements The statement if (true) { return false; } becomes if (true) return false;, also working for for and while statements
Change visibility of field or method to lower access The field public int field = 0 becomes private int field = 0 if it is not used outside class, also working for methods

Compatibility

Built for SDK version 2016.3, 2018.3, 2019.3, using JDK 8, those are the currently supported products, and is not expected to work in other products:

  • Intellij IDEA (ultimate and community)
  • PyCharm (professional and community)
  • PHPStorm
  • AndroidStudio
  • WebStorm
  • RubyMine
  • CLion

See issue #18 for a beta packaging that you can try in other products.

Backward compatibility

  • For SDK 2016.3, the latest version is Release 1.6.0+2016.3 (not maintained anymore).
  • For SDK 2018.3, 2019.3 and EAP (not released on plugin repository) the latest version is in the releases.

Eclipse configuration support

The save-actions plugin supports Eclipse configuration .epf files by the Workspace Mechanic Eclipse plugin (Java IDE only). You can specify a path to an Eclipse configuration file in the "Eclipse support" settings section to import it. The plugin will load the content of the file in the plugin configuration, and disable the plugin configuration options (the checkbox will be grayed out). Use the "reset" button to remove the import.

The plugin will stay in sync with your Eclipse configuration file. Not every features are present on either side, but the ones that are in common are supported.

You can find an example of an Eclipse configuration .epf file in the test resources.

# @title Save Actions
# @description Save Actions
# @task_type LASTMOD
file_export_version=3.0
/instance/org.eclipse.jdt.ui/editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
/instance/org.eclipse.jdt.ui/sp_cleanup.format_source_code=true
/instance/org.eclipse.jdt.ui/sp_cleanup.format_source_code_changes_only=false
/instance/org.eclipse.jdt.ui/sp_cleanup.organize_imports=true
/instance/org.eclipse.jdt.ui/sp_cleanup.remove_trailing_whitespaces=true
...

Other plugin compatibility

Some things to note when using other plugins with the Save Actions plugin:

  • IdeaVim: Since the Save Actions plugin do not trigger on the "Save Document" action (see usage), using :w to save in IdeaVim won't trigger the plugin, but using :wa will, since it calls the "Save All" action. See issue #222).
  • detekt: Using the detekt plugin breaks the Save Actions plugin, see issue #270.

Files location

  • idea.log: The log file the save actions plugin writes in. It contains debug information, prefixed with com.dubreuia.SaveActionManager. If you are using default locations, it would be in ~/.IntelliJIdeaVERSION/system/log/idea.log.
  • saveactions_settings.xml: The settings file is saved by project in the .idea folder. That file can be committed in git thus shared in your development team. If you are using the default locations, it would be in ~/IdeaProjects/PROJECT_NAME/.idea/saveactions_settings.xml

Contributions

Project management

There are 2 boards to track the issues (bug or features):

  • Agile Board - Save Actions - Ideas - Tracks your and our ideas for new features and the discussions around them. All the issues here are "closed"
  • Agile Board - Save Actions - Boards - Tracks the issues that are urgent enough and specified enough to be implemented. All the issues here are "open" except those that got implemented and will be release in next version, those are "closed" (and stay closed if they work once released).

When you submit an issue, it will be triaged into either board.

Contributors

Big thanks to all the contributors submitting issues, testing, and especially submitting pull requests. See contributors graph ♥️

Contributing

See CONTRIBUTING.

Releasing

See RELEASING.

Links

JetBrains plugin page

The plugin is in the JetBrains plugin repository, please take the time to rate it!

Issues

The plugin does not work? You want more features? You can ask me on twitter or create an issue on github.

Licence

MIT License

intellij-plugin-save-actions's People

Contributors

dansanduleac avatar dubreuia avatar fishermans avatar kedar-joshi avatar krasa avatar marcosbento avatar markiewb avatar mateuszwinnicki avatar rw00 avatar sabhtarshamojo avatar t-kameyama avatar wisajkin avatar zhujk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

intellij-plugin-save-actions's Issues

build.gradle editing with auto save on

When I edit a build.gradle file while the plugin is turned on, the code is formatted immediately as I type. This make it unusable. For example, I write:
println
and then press space, and the space is immediately removed.

This makes it pretty much impossible to code. As far as I know, this issue exist only on build.gradle files.

I'm using it in IDEA Ultimate 14.1.4.

Ability to perform custom actions on save

I'm not sure how feasible this is - but it'd be great if we could trigger an arbitrary menu item on save.

For example, it would be nice to be able to run "JSCS fix" on save

Problem with scala imports

Hi,

thank you for excellent plugin, as former Eclipse user I like it. However I have strange problems with my scala code. Auto save is configured to only organize imports, all other configurations are switched off. When I modify one line and I switch focus away from IntelliJ, the organize imports deletes some of imported class and the file cannot be compiled. This is quite unfortunate. I tried to do Code | Optimize imports manually but it works fine. Just when this action is called from the plugin it doesn't work as expected. Seems like there is some problem with interaction with scala plugin?

Intellij 2016.1.1, Scala plugin 3.0.2 and Save Actions plugin 0.7.

Unexpected file exclusions

I have two different machines each running the same IntelliJ (2016.1.2 built May 14th) and version 0.11 of the plugin.

On one machine everything works great. On the other I have no exclusions although I used to have some and have since removed all of them. On this machine nothing gets formatted. The IntelliJ log always shows something similar to this for each file:

C:/Users/pcalouch/Projects/TheraDoc_4.7.0/theraDocWeb/web/theradoc/app/components/features/aur/ar-details.component.html excluded in []

I have tried un-installing and re-installing the plugin with no luck on that machine. Could the plugin somehow be referencing some out of date exclusion? The debug doesn't tell what exclusion preventing the file from being formatted.

Any ideas? Thanks!

Exception: String index out of range: -1

Saw the following today. Had a gradle build running in the background.
IntelliJ 2016.1.2
OSX 10.11.5

String index out of range: -1 java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1931) at com.dubreuia.utils.PsiFiles.getUsableUrl(PsiFiles.java:40) at com.dubreuia.utils.PsiFiles.isPsiFileExcluded(PsiFiles.java:30) at com.dubreuia.SaveActionManager.isPsiFileEligible(SaveActionManager.java:50) at com.dubreuia.SaveActionManager.beforeDocumentSaving(SaveActionManager.java:36) at sun.reflect.GeneratedMethodAccessor574.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:117) at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:372) at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:359) at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:338) at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:42) at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:226) at com.sun.proxy.$Proxy22.beforeDocumentSaving(Unknown Source) at sun.reflect.GeneratedMethodAccessor574.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.a(FileDocumentManagerImpl.java:136) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.access$000(FileDocumentManagerImpl.java:86) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl$1.invoke(FileDocumentManagerImpl.java:114) at com.sun.proxy.$Proxy22.beforeDocumentSaving(Unknown Source) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl$4.run(FileDocumentManagerImpl.java:422) at com.intellij.pom.core.impl.PomModelImpl.guardPsiModificationsIn(PomModelImpl.java:380) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.b(FileDocumentManagerImpl.java:419) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.a(FileDocumentManagerImpl.java:393) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:313) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:292) at com.intellij.ide.SaveAndSyncHandlerImpl.doSaveDocumentsAndProjectsAndApp(SaveAndSyncHandlerImpl.java:140) at com.intellij.ide.SaveAndSyncHandlerImpl.saveProjectsAndDocuments(SaveAndSyncHandlerImpl.java:134) at com.intellij.ide.SaveAndSyncHandlerImpl$4.onFrameDeactivated(SaveAndSyncHandlerImpl.java:104) at com.intellij.ide.FrameStateManagerImpl.a(FrameStateManagerImpl.java:87) at com.intellij.ide.FrameStateManagerImpl.access$500(FrameStateManagerImpl.java:32) at com.intellij.ide.FrameStateManagerImpl$2$1.run(FrameStateManagerImpl.java:72) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:378) at com.intellij.util.Alarm$Request.run(Alarm.java:398) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:227) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:857) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:658) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:386) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Save actions should be applied to only a subset of source files

For instance, I don't want to format my xml or gradle file (I just lost 30 minutes as the plugin had formatted a gradle properties files..).

So, it would be nice to add a feature to provide a list of file name masks to apply the save actions to.

Default : all
Alternative : apply file masks :
the a field becomes enabled to enter a regexp list, comma separated like : .java,.xml

Don't reformat unmodified lines in IDEA 15

plugin is forcing style rules of javadoc (adding empty lines) and line break when overflowing specified Right margin
this happens in IDEA 15, in IDEA 14.1.5 plugin works fine

Add option to make project in save actions.

Just installed the save actions plugin and love it. One improvement that could be added is to add the option to make the project on save. IntelliJ currently has this option, but the option only performs a make if there is no code running. This makes hot swapping very annoying because you must manually press Cmd+F9 to make the project after each change. It would be great if save actions could also make the package after every save, regardless if code is running or not.

why only focus document can be used save actions? version 0.7

before upgrade to version 0.7, i used version 0.4, the can auto format all modified file (before do make/debug/other things), today i upgrade to version 0.7 and debug the source code, now why only focus document can be used save actions? when do make/debug can not used

@Override
public void beforeDocumentSaving(@NotNull Document document) {
    if (!SaveAllAction.TRIGGERED && isDocumentActive(document)) {
        LOGGER.debug("Document " + document + " is still active, do not execute");
        return;
    }
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (isPsiFileEligible(project, psiFile)) {
            processPsiFile(project, psiFile);
        }
    }
}

----------------Environment Version----------------
save actions plugin version 0.7
intellij idea version 15.0.3

Multiple open projects do not work properly

  • open 2 different project windows, A and B
  • edit a file in A, then switch to B [intellij syncs it and the plugin reformat it]
  • then B will ask for permission to modify the file in A

Support inspections

It would be nice if you could check inspections that would run and quick fix everything in changed files.

From comments to Eclipse Code Formatter plugin:
"I need Intellij to add the 'final' modifier everywhere possible. similar to Eclipse's: "Use modifier 'final' where possible" under "Save Actions"."

Module in a different path than project won't work

This is related to the fix for #1, because if you have a module whose code is in a different system path than the project -- the plugin won't work at all.

This is fixed (and tested against #1 also) by using

// only process the project that is currently active
final DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();
final Project project = DataKeys.PROJECT.getData(dataContext);
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);

And removing "isActive" and "isPsiFilePhysicallyInProject".

This commit has the fix + the "only modify if saveAll command is issued" fix from @krasa as well. I would do a PR, but there are some other changes as well that you might not want.

Support vim plugin

When using :w with the vim plugin, the save actions don't get executed.

Empty lines from properties files are always removed

Currently Save Actions plugin always removes empty lines from properties files.
This is not desirable for me- I use empty lines to separate file sections.

There are no options that control save actions for properties files (ignoring *.properties files does not work for me, most likely because of #29)

Update to java 8 and migrate to gradle

Add notes like the docker plugin "Note: For the plugin to work properly, your IDE should be started using Java 7 or a later version. For corresponding instructions, see Selecting the JDK version the IDE will run under."

Cannot run synchronous submitTransactionAndWait from invokeLater

18:30 Throwable Cannot run synchronous submitTransactionAndWait from invokeLater. Please use asynchronous submit*Transaction. See TransactionGuard FAQ for details. Transaction: Save All (Save all files and settings) of class com.intellij.ide.actions.SaveAllAction Unsafe modality: ModalityState:Optimize Imports 2026817985: running=false; canceled=false

Plugin killed by IntelliJ autosave

I like this plugin but had to disable it because it was slowing down my IntelliJ. This is caused by the annoying auto save feature of IntelliJ. As a result, the SaveActions is invoked too often rendering the editor unusable because of the frequent pauses while it's doing it's thing. I don't think this is the plug-ins problem in this case, but I am wondering if there is a trick to solve this?

Breaking gradle plugin

When opening and editing a gradle file with the save actions plugin activated, the "organize imports" task is running after each hit of a key.

Issue with certain C style block comment containing method

I have an interesting issue that I've narrowed down to being a C block style comment with a function within it. I thought at first it was caused by the function within the comment being recursive, but attempts at recreating the issue failed. As I'm not sure if it is an issue with the combination between SaveActions and/or EclipseFormatter. I have attached idea.txt file which currently doesn't have all too much information within it. Another thing to note is that it will continually say: 5:35:09 PM TestCodeFormat.java formatted successfully by Eclipse code formatter within the Intellij Even Log.

One thing to note is that if the comment is changed to single line comments // or it is not commented, it will successfully complete.

Intellij Information:

Version: IntelliJ IDEA 2016.1.2
Build #IC-145.971, built on April 29, 2016
JRE: 1.8.0_76-release-b162 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Eclipse Code Formatter: Version: 15.5.132.637.2
Save Actions: 0.9

The comment that causes the issue is below:

  /*private void printDeviceTree(CheckPointDevice device, String indent) {
     if (device == null) return;

     String text = device.getCpType().toString() + " " + device.getName() + ":" + device.getIpAddress();
     logger.error(indent + text);
     for (CheckPointDevice child : device.getChildren()) {
      printDeviceTree(child, indent + "  ");
     }
     }*/

NoSuchMethodError when rearrange code is activated

It seems the rearrange code processor is not shipped with every intellij version (it might come from a plugin).

Easy workaround: go in "File > Settings > Save Actions > Rearrange code" and uncheck the option. Your code will still reformat but won't reorder.

com.intellij.codeInsight.actions.RearrangeCodeProcessor.<init>(Lcom/intellij/codeInsight/actions/AbstractLayoutCodeProcessor;Lcom/intellij/openapi/util/Condition;)V
java.lang.NoSuchMethodError:
com.intellij.codeInsight.actions.RearrangeCodeProcessor.<init>(Lcom/intellij/codeInsight/actions/AbstractLayoutCodeProcessor;Lcom/intellij/openapi/util/Condition;)V
        at
com.dubreuia.processors.ProcessorFactory.getRearrangeCodeProcessor(ProcessorFactory.java:38)
        at
com.dubreuia.processors.ProcessorFactory.getSaveActionsProcessor(ProcessorFactory.java:21)
        at com.dubreuia.Component$1.beforeDocumentSaving(Component.java:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:114)
        at
com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:315)
        at
com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:302)
        at
com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:287)
        at
com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:41)
        at
com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:177)
        at com.sun.proxy.$Proxy20.beforeDocumentSaving(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.multiCast(FileDocumentManagerImpl.java:128)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.access$000(FileDocumentManagerImpl.java:87)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl$1.invoke(FileDocumentManagerImpl.java:116)
        at com.sun.proxy.$Proxy20.beforeDocumentSaving(Unknown Source)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl$4.run(FileDocumentManagerImpl.java:411)
        at
com.intellij.pom.core.impl.PomModelImpl.guardPsiModificationsIn(PomModelImpl.java:354)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocumentInWriteAction(FileDocumentManagerImpl.java:408)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocument(FileDocumentManagerImpl.java:382)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:303)
        at
com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:282)
        at
com.intellij.openapi.application.impl.ApplicationImpl.saveAll(ApplicationImpl.java:1452)
        at
com.intellij.ide.actions.SaveAllAction.actionPerformed(SaveAllAction.java:26)
        at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:614)
        at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:663)
        at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:513)
        at
com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:211)
        at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:546)
        at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Error: Attempt to modify PSI for non-committed Document

Opened the Maven Projects "Tab" and then this error came up:

Stacktrace:
Attempt to modify PSI for non-committed Document! java.lang.IllegalStateException: Attempt to modify PSI for non-committed Document! at com.intellij.pom.core.impl.PomModelImpl.a(PomModelImpl.java:325) at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:146) at com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:167) at com.intellij.psi.impl.source.tree.CompositeElement.addChild(CompositeElement.java:660) at com.intellij.psi.impl.source.tree.CompositeElement.addChildren(CompositeElement.java:767) at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.addChildren(CodeEditUtil.java:81) at com.intellij.psi.impl.source.tree.CompositeElement.addInternal(CompositeElement.java:544) at com.intellij.psi.impl.source.tree.java.ModifierListElement.addInternal(ModifierListElement.java:45) at com.intellij.psi.impl.source.PsiModifierListImpl.setModifierProperty(PsiModifierListImpl.java:239) at com.intellij.psi.util.PsiUtil.setModifierProperty(PsiUtil.java:1108) at com.intellij.codeInspection.localCanBeFinal.LocalCanBeFinal$AcceptSuggested.applyFix(LocalCanBeFinal.java:341) at com.intellij.codeInspection.localCanBeFinal.LocalCanBeFinal$AcceptSuggested.applyFix(LocalCanBeFinal.java:325) at com.dubreuia.processors.InspectionProcessor$InspectionWriteQuickFixesAction.writeQuickFixes(InspectionProcessor.java:82) at com.dubreuia.processors.InspectionProcessor$InspectionWriteQuickFixesAction.run(InspectionProcessor.java:74) at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:162) at com.intellij.openapi.application.RunResult.run(RunResult.java:35) at com.intellij.openapi.command.WriteCommandAction$2.run(WriteCommandAction.java:108) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:124) at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99) at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:103) at com.intellij.openapi.command.WriteCommandAction.access$000(WriteCommandAction.java:34) at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:85) at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:723) at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:82) at com.dubreuia.processors.InspectionProcessor$1.run(InspectionProcessor.java:48) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:345) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:329) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at com.intellij.ide.IdeEventQueue.h(IdeEventQueue.java:857) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:658) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:386) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Add locked files, undo support and compilation support

From #30

private final static Set<Document> documentsToProcess = new HashSet<Document>();
private static VirtualFile[] fileToCompile = VirtualFile.EMPTY_ARRAY;

// The plugin extends FileDocumentManagerAdapter.
// beforeDocumentSaving calls reformatAndCompile
private static void reformatAndCompile(
        @NotNull final Project project,
        @NotNull final Document document,
        @NotNull final PsiFile psiFile) {
    documentsToProcess.add(document);
    if (storage.isEnabled(Action.compileFile)
        && isDocumentActive(project, document)) {
        fileToCompile = isFileCompilable(project, file);
    }
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
                @Override
                public void run() {
                    if (documentsToProcess.contains(document)) {
                        documentsToProcess.remove(document);
                        if (storage.isEnabled(Action.optimizeImports)
                                || storage.isEnabled(Action.reformatCode)) {
                            if (storage.isEnabled(Action.optimizeImports)) {
                                new OptimizeImportsProcessor(project, psiFile)
                                    .run();
                            }
                            if (storage.isEnabled(Action.reformatCode)) {
                                new ReformatCodeProcessor(
                                        project,
                                        psiFile,
                                        null,
                                        ChangeListManager
                                            .getInstance(project)
                                            .getChange(psiFile.getVirtualFile()) != null)
                                                .run();
                            }
                            PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
                            psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
                            psiDocumentManager.commitDocument(document);
                        }
                    }
                }
            });

            if (fileToCompile.length > 0) {
                if (documentsToProcess.isEmpty()) {
                    compileFile(project, fileToCompile);
                    fileToCompile = VirtualFile.EMPTY_ARRAY;
                }
            } else if (storage.isEnabled(Action.makeProject)) {
                if (documentsToProcess.isEmpty()) {
                    makeProject(project);
                }
            } else {
                saveFile(project, document, psiFile.getVirtualFile());
            }
        }
    }, project.getDisposed());
}

private static void makeProject(@NotNull final Project project) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            CompilerManager.getInstance(project).make(null);
        }
    }, project.getDisposed());
}

private static void compileFile(
        @NotNull final Project project,
        @NotNull final VirtualFile[] files) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            CompilerManager.getInstance(project).compile(files, null);
        }
    }, project.getDisposed());
}

private static void saveFile(
        @NotNull final Project project,
        @NotNull final Document document,
        @NotNull final VirtualFile file) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
            if (fileDocumentManager.isFileModified(file)) {
                fileDocumentManager.saveDocument(document);
            }
        }
    }, project.getDisposed());
}

File path exclusions get ignored if IntelliJ Project Files are in a different file path than the Source Code Files

in my setup I have something like this:

IntelliJ Project Setup:
C:\Users\pcalouch\Projects\My Project (IntelliJ project files here)
C:\Users\pcalouch\Repos\My Project (index.cfm and other source code files here)

If I use .*.cfm as a file path exclusion index.cfm is still formatted when pressing Ctrl+S. However it works if I set me project up like this:

C:\Users\pcalouch\Projects\My Project (IntelliJ project files along with index.cfm and other source code files here)

I thinking it could be something similar that caused this issue: Nothing happens in IntelliJ 14 Ultimate #4

Nothing happens in IntelliJ 14 Ultimate

I installed the plugin, restarted IntelliJ, enabled Save actions in its config pane, but it does not seem to do anything. I tried

  • restarting IntelliJ: no difference
  • different ways of saving: ctrl-s, triggering a build, quitting IntelliJ: no actions
  • looking in idea.log: Save Action plugin is enabled, but no further output from the plugin.

Any idea?

btw. this plugin is a great idea ;-)

Save actions does not save file after formatting

If the options to reformat code and organize imports are enabled and at least reformat code is triggered then the code is reformatted but the file is not saved so you have to press Ctrl+S twice.

Steps to reproduce: (Tested in a java file and java script file)
1: Write some correctly formatted code.
2: Add after a semicolon some more code so you get a line like
System.out.println("foo");System.out.println("bar");
3: Press Ctrl+S
Expected result:
The code shall look like
System.out.println("foo");
System.out.println("bar");
and
The file shall be saved.

Actual result:
The code looks like
System.out.println("foo");
System.out.println("bar");
and
The file is NOT saved.

Add final to method parameters

Thanks for updating the save actions to 0.9. One thing is still annoying and not what I expected updating code that had been written with eclipse.
The option "Add final to local variable" I would like to check, because I want the final added to:
String text = object.getName();
(Otherwise checkstyle will complain.)
But I do not need the final added to all parameters of all method declarations.
Gives many superflous code changes. Please do not include that in this option.
Perfectly all right would be a separate option "Add final to method parameters" which I could uncheck if desired.

Plugin should be enabled for each project separately

From the plugin page comment section:

andyrozman
2015-05-04 11:34:21
Great plugin... Just something I wanted when I switched from Eclipse... While it's great, there is one thing missing... Plugin should be enabled for each project separately... I am using my IntelliJ for two different project, I need Save actions for one of them but not for the other one...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.