question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add reformat support to Rider

See original GitHub issue

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)

_Originally posted by @bobvandevijver in https://github.com/dubreuia/intellij-plugin-save-actions/issues/18#issuecomment-426065888_

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
dubreuiacommented, Oct 3, 2018

(copy pasted issue comments from #18 for clarity)

1reaction
van800commented, Oct 5, 2018

Please consider this code: https://github.com/JetBrains/resharper-unity/blob/183/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/SaveAllTracker.kt#L23 If we use this datacontext (inside beforeActionPerformed), instead of active editor to datacontext, then all dirty files should get formatted and saved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure formatting rules | JetBrains Rider Documentation
To explore settings and configuration files that affect formatting in the current file, press Ctrl+Shift+A or choose Help | Find Action from the...
Read more >
Managing and Applying Code Formatting Rules - JetBrains
JetBrains Rider provides several ways to reformat existing code. In short, you can always use Ctrl+Alt+Enter , but there are a few details...
Read more >
JetBrains Rider on Twitter: "Reformat and Cleanup on Save It ...
Reformat and Cleanup on Save It allows you to have your code reformatted and tidied up whenever you explicitly invoke Save or Save...
Read more >
C# Rider How to disable format/reformat in a block of code?
... add an .editorconfig to your project to customize the formatting behavior. See https://www.jetbrains.com/help/rider/Using_EditorConfig.
Read more >
dotnet-format in JetBrains Rider - Pause
These tools can be added to “any” git based flow, and can expect identical formatting across different code editors! No more “Rider/ReSharper” ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found