dubreuia/intellij-plugin-save-actions

Add support to all intellij products

jclx opened this issue ยท 91 comments

jclx commented

If you add
com.intellij.modules.lang

to the plugin.xml it will on all intellij products like webstorm.

Great plugin btw.

Thanks, I'll add that, but I'll need to test it in all intellij products.

From twitter: "Hi there, I just installed Save Actions on phpstorm 9.0.2 but cannot find the settings as described in the documentation."

Lots of demand for this:

  • PyCharm (#22)
  • Android Studio #31
  • PHPStorm #32

Guess the php webstorm support never made it in? Was really excited when I found this plugin and it installed fine, just cannot find the settings anywhere.

Hey @XXChester I'm working on bringing the plugin to all products right now, PhpStorm will soon be supported. I closed specific issues because they are duplicate with this one (I'll release it for all products at the same time).

๐Ÿ‘ Awesome. I thought it was abandoned date, glad to hear it is not.

Glad to hear you are working on making it work on a variety of platforms. Is it possible to release a port as soon as its finished instead of waiting for release until all other platforms are done? This would help so much. I personally feel that my quality of codes degrades without SaveActions. I really want this on Android Studio.

Is Android Studio a JetBrains product? I'm testing for:

  • Intellij IDEA
  • PhpStorm
  • WebStorm
  • PyCharm
  • RubyMine
  • AppCode
  • CLion
  • DataGrip (maybe?)

The branch all-products works, I just haven't properly tested it yet

Dubreuia, Android Studio is based on Intellij IDEA. So practically the IDEA extension/plugins should work but it doesn't - in fact, and this is where the troubles com in, it cant even be downloaded as a plugin from the Plugin repository browser inside Android Studio. Its just not listed. I just verified this. Appears in Idea (version 15) but doesnt in Android Studio (lastest) 2.1.1. As its entirely based on Idea I would assume its not too much effort to enable it for Android Studio. Anyway I keep waiting :) Keep up the good work!

krasa commented

You need to put <depends>com.intellij.modules.platform</depends> into plugin.xml .
edit: nevermind, you already did in that branch :)

@krasa Thanks already done! The problem is that I have Java specific elements, so I need to split the plugin in two parts so it doesn't crash on startup with PyCharm, etc.

@sgeier OK it is not a JetBrains product but it should work too, note to self : https://developer.android.com/studio/index.html

I should release the all-product version this weekend if all goes well

@dubreuia Any update on the release of the all-product branch? We'd like to start using it across the dev team here as soon as it's ready

I'm happy to support in any testing as well, let me know. ๐Ÿ‘

Actually it's already ready, but I don't have time to test it so I didn't release it. I'll send you the jar so you can test if you want.

save-actions.zip

Unzip, inside you have a .jar that you can import by hand in Intellij (Settings > Plugins > Import from jar). It is version 0.12-RC, it is based on 0.10 (not the latest available, you have probably on 0.11 right now).

@dubreuia I can confirm that zipped version works on WebStorm 2016.2.3.

The zip file works fine in WebStorm 2016.2.4. Thanks for this awesome plugin.

Thanks for your feedback, I'll make that available on the Jetbrains plugin repository.

Ok with PHPStorm!

F21 commented

Doesn't work with Gogland 1.0 EAP (163.10615.6) for golang using 0.12. Would be awesome if it could be supported ๐Ÿ˜„

Any way we could get this added to the Jetbrains' plugin repository for PhpStorm?

Hey @spencero91, try the save-actions zip I uploaded in this issue, you can import it directly in PhpStorm.

I don't want to upload it to the plugin repository just now, I haven't tested it in all products, and I don't have time to correct all the issues that are opened only for intellij...

The code is on branch master-all-product.

Keep me posted if that works for you

Check #69 for licences to test in all products

For AS 2.3 I was able to download the latest version from https://plugins.jetbrains.com/plugin/7642-save-actions and then just install from within android studio:

Android Studio (Menu) -> Preferences -> Plugins -> Install plugin from disk...

Works just fine for me. The settings for it can be found under Other Settings

Yeah it works as-is for Android Studio because it is a Java IDE. The other products will need the zip that is packaged in this issue.

Just tested in WebStorm 2017.1. Appears to work. Suggestions:

  • Include an option to reformat when the editor autosaves. The behavior I'm currently seeing is that reformatting is only taking place if I hit Ctrl-S/Cmd-S.
  • Place language-specific configuration options in language-specific sections. For example, "Organize Imports", "Rearrange fields ..." and "Compile File" only make sense for compiled languages (Java, TypeScript, etc), but they don't make any sense for JavaScript files.

Great plugin, especially for large teams! ๐Ÿ‘

Hey @matthewadams thanks for the testing and the tweet I appreciate it.

Include an option to reformat when the editor autosaves. The behavior I'm currently seeing is that reformatting is only taking place if I hit Ctrl-S/Cmd-S.

Actually, that should work. The autosave in Intellij is somewhat finicky, the easiest way to force it is by losing focus. Try (1) change a formatting or add unused import (2) click on another non-intellij window. It should reformat. That's the whole point of the plugin: not to think about it.

Place language-specific configuration options in language-specific sections. For example, "Organize Imports", "Rearrange fields ..." and "Compile File" only make sense for compiled languages (Java, TypeScript, etc), but they don't make any sense for JavaScript files.

There is already a classification, the version you are using doesn't have the Java quick fixes. The one I left are, for me, available for all languages. It is based on the langage-based processors in the Intellij platform.

It is also very hard to classify language like this, for instance vanilla ES6 have imports but not the previous versions...

Yes, it worked when WebStorm lost focus. Maybe you should open an issue with JetBrains to get more consistent notification of autosave so that the behavior is consistent, but that's up to you. Is there a more standard place from which to download the plugin than this issue now that it's been confirmed to work on other JetBrains products? Thanks again!

Any chance getting a recent version of the plugin with the patch? I'm looking for support in pycharm and CLion. Sorry if I've overlooked something, but IMO the link provided above refers to a patched v11 of the plugin.

Hey @afwlehmann I'll try to repackage it with a recent version of the plugin. Honestly, not much changed for non-Java languages in recent versions.

I won't release it on the official plugin repository, I don't have time to maintain the plugin for Intellij IDEA, if I support all product I'll have thousand of new users I don't have time to support

@dubreuia Thanks a lot!

@afwlehmann I repackaged the plugin for all products on version 0.17. This time I merged the code to master, but didn't activate the plugin for all product (the line is commented in the plugin.xml file). It is not in the plugin repository yet but I might add it soon.

I tested in PyCharm and it seems to work. Keep me posted if it works for you.

save-actions_0.17.jar.zip

edit: you need to unzip the jar, then import in pycharm or other

Currently tested:

  • PyCharm: OK
  • AndroidStudio: OK (BUT exception quick fixes do not work, offending line META-INF/plugin.xml:73 do not load the java xml)

@dubreuia That's very much appreciated! I'll give it a try as soon as possible and let you know. Thanks :)

Works like a charm, thank you very much for your time and effort! (Tested on PyCharm / Linux, I'll give it another try on CLion in a couple of days)

Thanks @afwlehmann I'll slowly add supported products then. I'll add PyCharm for now

I can confirm it work as expected on the latest PyCharm on MacOS

New version 0.18 should work in PyCharm and PhpStorm

  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)
  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • Rider (todo)
  • RubyMine (todo)
  • WebStorm (todo)

Version 0.21 (https://github.com/dubreuia/intellij-plugin-save-actions/releases/tag/v0.21) adds official support to AndroidStudio. I'd like to do WebStorm after

  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • AndroidStudio (OK)
  • WebStorm (todo)
  • Rider (todo)
  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)
  • RubyMine (todo)

If you are using that plugin, could you rate it on https://plugins.jetbrains.com/plugin/7642-save-actions

@dubreuia: 0.21 works in

WebStorm 2017.2.3
Build #WS-172.3968.27, built on August 29, 2017
JRE: 1.8.0_152-release-915-b11 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

Except #110

OK I'll correct #110 and add support for WebStorm when I have time

Is there a hurdle to just adding CLion also?

Hey @studgeek I've given up on testing the plugin on all Jetbrain's products, I let users do that and report it here.

You can install the plugin in CLion by downloading the latest version from https://github.com/dubreuia/intellij-plugin-save-actions/releases and then doing "File > Settings > Plugins > Install plugin from disk" and choosing the jar you downloaded.

Added WebStorm in https://github.com/dubreuia/intellij-plugin-save-actions/releases/tag/v0.23

  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • AndroidStudio (OK)
  • WebStorm (OK)
  • Rider (todo)
  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)
  • RubyMine (todo)

Just tested and it seems to work fine in RubyMine :)
(too bad it's not the plugin I was looking for ๐Ÿ˜‚)

Hey @d4rky-pl, thank you for telling us! I hope you'll find what you are looking for :)

I'll add RubyMine support when I release next version

Added RubyMine in https://github.com/dubreuia/intellij-plugin-save-actions/releases/tag/v0.25

  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • AndroidStudio (OK)
  • WebStorm (OK)
  • RubyMine (OK)
  • Rider (todo)
  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)

It's not working for me on WebStorm 2017.2.5

Hey @pablogarciamiranda thanks for the update. I'll check it out.

Hey @pablogarciamiranda thanks for the update. I'll just tested in "WebStorm 2017.3.4 Build #WS-173.4548.30, built on January 30, 2018" and it works. What is the problem?

Rider support would be great since this plugin is very helpful.

Hey @ptr1120, would you mind testing it? Download the jar at https://github.com/dubreuia/intellij-plugin-save-actions/releases/tag/v0.26, then "File > Settings > Plugins > Install plugin from disk..." and import the jar, restart and see if it works for you.

If it works, I'll add it to the supported products and you'll see it in "Browse Repository" in Intellij. Thanks.

Thanks, @dubreuia, installed the plugin, plugin settings are available, but nothing happens during save action execution. The idea log says:

10:19:18.884 | INFO  | FileBasedIndexProjectHandler   | Reindexing refreshed files: 0 to update, calculated in 26ms
10:19:38.861 | DEBUG | SaveActionManager              | Running SaveActionManager on DocumentImpl[file://<myFolder>/MyFile.cs]
10:19:38.871 | DEBUG | SaveActionManager              | Running processors [RearrangeCode (true), OptimizeImports (true), ReformatAllText (true)], file RIDER_SOURCE_CODE_FILE, project Project '<myFolder>' NopCommerce
10:19:41.178 | INFO  | ProjectRootManagerComponent    | project roots have changed
10:19:42.140 | INFO  | PerformanceWatcher             | Pushing properties took 431ms; general responsiveness: ok; EDT responsiveness: 1/1 sluggish
10:19:42.280 | INFO  | PerformanceWatcher             | Indexable file iteration took 139ms; general responsiveness: ok; EDT responsiveness: ok
10:19:42.280 | INFO  | UnindexedFilesUpdater          | Unindexed files update started: 1 files to update
10:19:42.576 | INFO  | PerformanceWatcher             | Unindexed files update took 296ms; general responsiveness: ok; EDT responsiveness: ok
10:19:43.905 | INFO  | SolutionLifecycleHost          | Full warm solution load with caches took 34889 milliseconds.
10:19:47.571 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@7398727d
10:19:47.818 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@4c84eb97
10:19:47.988 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@6c8722f
10:19:48.138 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@15f1dda4
10:19:48.270 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@5f20dfe0
10:19:48.391 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@41a33d8e
10:19:48.512 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@5309b51
10:19:48.639 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@75104dcf
10:19:48.753 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@1aa13d13
10:19:48.894 | DEBUG | SaveActionManager              | Running SaveActionShortcutManager on com.intellij.openapi.actionSystem.AnActionEvent@111d84c5
10:21:55.025 | INFO  | ShowFilePathAction             | 
Exit code 1
` ` ` 

I obfuscated folder and filename, but the original values where correct.

Thanks you for testing @ptr1120, I'll have to debug it. I'm updating:

  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • AndroidStudio (OK)
  • WebStorm (OK)
  • RubyMine (OK)
  • Rider (settings OK - reformat KO)
  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)

I tried the Rider support also. Settings are shown fine, but nothing except https://youtrack.jetbrains.com/issue/DEXP-381630 happends on Save.

For me, using Rider on macOS, after downloading and pointing it at the jar, (unlike above) I don't get any errors in the Event Log, and I see the preference pane and it saves fine (like above).
Unfortunately it also seems not to change anything on save, regardless of the settings I enable.

this plugin doen't work for clion.

Ok I'll check Rider dans Clion before releasing 1.1.0, which should be by the end of the month

CLion works. A bit too well since it deletes used imports but formatting is OK. See #180.

Actually, Rider is not officially supported and CLion works so we're good for 1.1.0, no regression.

I'm also looking forward to Rider support, but you say it's not supported? How come?

Edit: Adding missing not

"ist not"
Maybe in 1.2.0?

@bobvandevijver Rider is not supported because I don't have time to write the code. You can submit a PR to add Rider support anytime.

Right. I mistakenly assumed you meant not supported from JetBrains, as you wrote "officially". I might take a look (although I've never touched JetBrains plugins before)

Sorry for the mixup, I meant "If it is not in https://github.com/dubreuia/intellij-plugin-save-actions#compatibility, it might work but I haven't tested it"

Documentation on development environment setup: https://github.com/dubreuia/intellij-plugin-save-actions#contributing

It seems that the plugin is doing it's job in Rider as you should expect, as it calls the run method of com.intellij.codeInsight.actions.ReformatCodeProcessor. The call itself simply doesn't do the formatting (it doesn't throw anything either), and I do not see anything weird during it's execution, so I'm stuck ๐Ÿ˜ž

@bobvandevijver Thank you for the debug. I'm pretty sure the reformat in Rider and PyCharm (maybe others) is not done by ReformatCodeProcessor. We'll need to provide specific implementation for those products (like META-INF/plugin-java.xml for Java), and call the proper formatter on save.

I tried some more with the plugin, and it seems that the whole CodeStyleManager simply doesn't work in Rider. It has probably something to do with the backend connection with ReSharper, which is responsible for the formatting/optimizations.

I can trigger the reformat with the following, ugly hack:

ActionManager.getInstance().getAction("ReformatCode")
    .actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(),
        ActionPlaces.UNKNOWN, new Presentation(), ActionManager.getInstance(), 0));

This triggers the following logging in the frontend, which is the same when triggered from the menu/shortcut:

23:05:45.647 | INFO  | RiderActionOverride            | Executing ReSharper action 'RiderReformatCode'
23:05:45.647 | INFO  | RiderActionHandlers            | >> Begin backend 'RiderReformatCode' action session
23:05:45.649 | INFO  | RiderActionHandlers            | << End backend 'RiderReformatCode' action session

It does not play nice with any other action being executed simultaneously (such as "OptimizeImports"), so it is in no way an suitable solution.

So, it looks like the ReSharper action is simply not triggered/created when the CodeStyleManager is used. Do we really need to create a ReSharper plugin, which communicates with the frontend? (see https://www.jetbrains.com/help/resharper/sdk/Products/Rider.html). I cannot find really relevant documentation on this issue.

There are also some other issues when compiling the plugin with the Rider SDK, mostly missing classes, so I'm not sure if it's even possible to compile the current plugin for Rider. See bobvandevijver@0a1d0af for the classes I needed to remove in order to being able to build for Rider.

Edit: I also created a ticket at JetBrains: https://youtrack.jetbrains.com/issue/RIDER-20225

(btw, if you want to open an another issue for this discussion just let me know)

@bobvandevijver
I guess it should be something like:
val actionId = ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_REFORMAT)

var component  =  project.getComponent<EditorImpl>().component
var dataContext = DataManager.getInstance().getDataContext(component)
fun executeAction(actionId: String, dataContext: DataContext) {
    frameworkLogger.info("Execute action: '$actionId'")
    val actionManager = ActionManagerEx.getInstanceEx()
    val action = actionManager.getAction(actionId)
    //requireNotNull(action) { "action is null" }

    val event = AnActionEvent.createFromAnAction(action, null, "", dataContext)
    action.beforeActionPerformedUpdate(event)

    //require(event.presentation.isEnabled) { "presentation.isEnabled is false for $actionId" }

    actionManager.fireBeforeActionPerformed(action, event.dataContext, event)
    action.actionPerformed(event)
    actionManager.fireAfterActionPerformed(action, event.dataContext, event)
}

I will ask colleagues about calling reformat and OptimizeImports simultaneously.
I assume you are calling OptimizeImports with similar code above.
Surprisingly "OptimizeImports" is not listed in IdeActions, so just hardcode it.

Yes, I used the same structure for "OptimizeImports".

I just used your examples (needed to retrieve the editor component with JComponent component = FileEditorManager.getInstance(myProject).getSelectedTextEditor().getComponent(); though), the result is the same: only one action is executed, which is the once that is called later.

Another thing noteworthy is the fact that your example triggers the save action handlers twice, while the version I posted earlier didn't... not sure what causes that though.

Another question I have with this solution: it probably doesn't support VCS changed code either... I really hope that JetBrains will just implement the CodeStyleManager in Rider ๐Ÿ˜…

@bobvandevijver I have asked about multiple commands but no workaround for now.
Not sure, what do you mean about vcs changed code. If you want to reformat everything in solution, you need to put solutionNode of SolutionExplorer to context like:

        val viewPane = SolutionExplorerViewPane.getInstance(project)
        val solutionNode = viewPane.model.root.children.filterIsInstance<SolutionExplorerModelNode>().single()

        val contextData = mapOf(
            Pair(PlatformDataKeys.SELECTED_ITEM.name, solutionNode),
            Pair(PlatformDataKeys.PROJECT.name, project),
            Pair(ProjectModelDataKeys.SOLUTION_VIEW.name, viewPane))

        var dataContext= SimpleDataContext.getSimpleContext(contextData, null)

Not sure, what do you mean about vcs changed code.

@van800 To reformat only changed lines according to your VCS (eg. git) (which is one of the options of the ReformatCodeProcessor, which uses the CodeStyleManager internally)

@van800 @bobvandevijver If you have an almost-working solution (or various possible solutions), could you post a PR with "WIP" prefix so we keep that code somewhere.

Also I'm creating an issue for Rider (see #198)

Any plan to support GoLand IDE? It would be awesome to support GoLand IDE.

Hey @hwangjr, would you mind downloading the latest jar in the release section (https://github.com/dubreuia/intellij-plugin-save-actions/releases/tag/v1.2.0) and test it in GoLang IDE. It might actually work. Can you report back on that? Thanks.

  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • AndroidStudio (OK)
  • WebStorm (OK)
  • RubyMine (OK)
  • Rider (settings OK - reformat KO)
  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)
  • GoLand IDE (todo)

@dubreuia yes, it works. Can you add to jetbrains plugin center? we can download from repositories directly.

Ok @hwangjr I've added GoLand IDE to the list of compatible IDEs. You should uninstall the local plugin and reinstall it from the plugin repository so you get updates. Thanks!

  • IntelliJ IDEA (OK)
  • PhpStorm (OK)
  • PyCharm (OK)
  • AndroidStudio (OK)
  • WebStorm (OK)
  • RubyMine (OK)
  • GoLand IDE (OK)
  • Rider (settings OK - reformat KO)
  • AppCode (todo)
  • CLion (todo)
  • DataGrip (todo)

OK, Thanks.

is it possible to vote for AppCode? ๐Ÿ˜„ I would be also happy to test it

is it possible to vote for AppCode? ๐Ÿ˜„ I would be also happy to test it

you can test it then tell @dubreuia the test result.

@hwangjr @dubreuia looks like it works fine in AppCode 2019.1, tomorrow will test it more

Found that some options are not available, I especially miss "No action if compile errors".
Screenshot 2019-05-16 at 10 36 49

I looked for Save Actions in the marketplace and it doesnt exist? Does this support rider?

image

@bbakermmc I've created a plugin which "works" (is sometimes errors, only has the basic capabilities), which you can find here: https://github.com/dubreuia/intellij-plugin-save-actions/files/2449110/Save.Actions-0.0.1.zip. See #198 for more information.

@ned1988 Thanks for testing. The option "No action if compile errors" requires a compiler, and since it is platform specific (java, python, etc.) I haven't coded this already outside the Java ecosystem. There's a "core" plugin, used everywhere, and a "java" plugin, used for java products. We'll need "language" plugin for each product we want to fully support, Rider included. If it woks fine I'll mark it as supported then.

I'm thinking of splitting this issue for each products, this issue is 4 years old...

Any update?

Hello @keyvchan ! I don't have time to work on this, but PRs are welcomed. Which product do you use?

I've created 3 issues for each of Rider, AppCode and CLion. Can you guys go vote and post in the issues to see which is needed?

I'm closing this issue. Thanks