Delegating formatting to an external formatter
I'm at Google working on an IJ plugin for google-java-format. It's the first source code formatter which our Java-style team has blessed as doing an acceptable job, and we're making an effort to refine it and push it into as many of our coding environments as possible.
I've experimented with three possible approaches, none of which feel ideal. Hoping I could get some advice here!
Implement a specialized CodeStyleManager which can delegate to our GJF library for Java files, or to the default CodeStyleManagerImpl for everything else.
This appears to be the approach I found in a couple projects on GitHub, but feels a little heavy-handed and possibly brittle.
Suppress IJ's Java formatting with a LanguageFormattingRestriction extension, register a PostFormatProcessor extension which performs formatting with GJF
This seems to be the cleanest solution, but the LanguageFormattingRestriction will cause the "Reformat code" menu item to be disabled in some situations, e.g. when the user highlights a Java file in the Project tree and wants to reformat it.
Suppress IJ's Java formatting with a no-op FormattingModelBuilder extension, register a PostFormatProcessor extension which performs formatting with GJF
There doesn't seem to be a straightforward way to implement a no-op FormattingModelBuilder or no-op FormattingModel.
请先登录再写评论。
BTW, we were able to upstream a change to Eclipse that makes formatters pluggable:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=449262
I just want to clarify (as a member of the aforementioned style team) that this is not a knock against IntelliJ's native formatting capabilities. The crux of the matter is that we are stuck at Google with supporting users who use a mix of IntelliJ and 4 other inferior editors :-) and we desperately wish to have One Canonical Style To Rule Them All -- to get absolute *perfect* agreement between the formatting produced by all these editors. So we're modifying them all to use the exact same tool to achieve victory.
Why don't you just use Eclipse formatter? Both Netbeans, IntelliJ and Eclipse should be able to produce identical formatting.
We actually lost years clinging to the hope that with enough hacks to eclipse's formatter it could be made to work acceptably.
In any case, whether our One Formatter To Rule Them All used eclipse or not, I think we'd still have the same set of requests here, right?