dubreuia / intellij-plugin-save-actions

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

Add support to all intellij products #18

Closed jclx closed 4 years ago

jclx commented 9 years ago

If you add

com.intellij.modules.lang

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

Great plugin btw.

dubreuia commented 6 years ago

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

dubreuia commented 6 years ago

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?

ptr1120 commented 6 years ago

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

dubreuia commented 6 years ago

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.

ptr1120 commented 6 years ago

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.
dubreuia commented 6 years ago

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

van800 commented 6 years ago

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

qayshp commented 6 years ago

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.

findpikachu commented 6 years ago

this plugin doen't work for clion.

dubreuia commented 6 years ago

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

dubreuia commented 6 years ago

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

dubreuia commented 6 years ago

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

bobvandevijver commented 6 years ago

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

Edit: Adding missing not

MartinX3 commented 6 years ago

"ist not" Maybe in 1.2.0?

dubreuia commented 6 years ago

@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.

bobvandevijver commented 6 years ago

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)

dubreuia commented 6 years ago

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

bobvandevijver commented 6 years ago

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 😞

dubreuia commented 6 years ago

@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.

bobvandevijver commented 6 years ago

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 https://github.com/bobvandevijver/intellij-plugin-save-actions/commit/0a1d0afd4a2984381e0016de3e0ebedb1dcd368d 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)

van800 commented 6 years ago

@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.

bobvandevijver commented 6 years ago

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 😅

van800 commented 6 years ago

@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)
bobvandevijver commented 6 years ago

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)

dubreuia commented 6 years ago

@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)

hwangjr commented 6 years ago

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

dubreuia commented 5 years ago

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.

hwangjr commented 5 years ago

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

dubreuia commented 5 years ago

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!

hwangjr commented 5 years ago

OK, Thanks.

denys-meloshyn commented 5 years ago

is it possible to vote for AppCode? 😄 I would be also happy to test it

hwangjr commented 5 years ago

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.

denys-meloshyn commented 5 years ago

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

denys-meloshyn commented 5 years ago

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

bbakermmc commented 5 years ago

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

image

bobvandevijver commented 5 years ago

@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 https://github.com/dubreuia/intellij-plugin-save-actions/issues/198 for more information.

dubreuia commented 5 years ago

@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.

dubreuia commented 5 years ago

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

keyvchan commented 4 years ago

Any update?

dubreuia commented 4 years ago

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

dubreuia commented 4 years ago

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