Help Developing Plugin (Reformat File Using Bash/gradle Command)
Answered
Hello,
I'd like to develop a plugin which is able to reformat code by executing a bash/gradle command e.g. `./gradlew formatApply` on file save or via menu item select. This command can either change the file passed in directly or else output the result to stdout.
My questions are:
- What 'type' of plugin is this? Should this be an 'action' that just executes the command, or else an 'external code formatter '(https://plugins.jetbrains.com/docs/intellij/code-formatting.html#external-code-formatter)?
- Is there documentation out there telling me what properties certain classes have? For example, how would I get the absolute path of a file in an action / external formatter?
- For this, would it be possible to 'override' the included "Reformat code" functionality in Intellij, either by replacing it or disabling 'format on save' automatically when the plugin is added? Or should I just have it as a separate action?
Thank you for the help!
Please sign in to leave a comment.
Ahh, it looks like I may just want to copy https://upsource.jetbrains.com/idea-ce/file/idea-ce-b52da31a47dbba814f668683810ea38b09536985/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java?
If you want to "replace" the builtin format action in the IDE, using
com.intellij.formattingService
extension point is the correct way.See https://plugins.jetbrains.com/intellij-platform-explorer?extensions=com.intellij.formattingService for existing plugins on how to use it.