Run external tool when formatter is called


I'm working on enhancing the GO language plugin from here:
GO has a nice command called 'go fmt' which you can invoke and it will format the code according to the standards.
My quetion is: how do I make it so that whenever a format command or a file is saved the plugin runs that command automatically?

Thank you.

Comment actions Permalink

You don't, really. First of all, in IntelliJ IDEA, users are never meant to save files explicitly, so we're really reluctant to add any features which are triggered by the user pressing the Save button. (Of course, you can implement this in your plugin, but this would be inconsistent with the behavior of other IDEA features.) Second, the formatter is triggered in many different situations, not just when the Reformat action is invoked (for example, every time a user presses Enter, the formatter is used to calculate the correct indent for the new line.) So you pretty much have to reimplement 'go fmt' on top of IntelliJ IDEA's formatter engine anyway, and once you do that, there's not much benefit in implementing the possibility to call the original one.

Comment actions Permalink

Hi Dmitry, thanks for your quick reply.
So I'm better of fixing the internal formatter in this case.

Thanks, have a nice weekend.


Please sign in to leave a comment.