groovy-eclipse icon indicating copy to clipboard operation
groovy-eclipse copied to clipboard

java formatting applied when trying to format from outside of an editor

Open webczat opened this issue 9 years ago • 3 comments

Hello.

It seems that if you try to perform code formatting from outside of the source editor for groovy, java formatting is performed. I had a problem that in my groovy script, many lines were joined (they did not have semicolon at ends). Also tested by creating a file with extremely long comment. Formatting from inside had no effect, but formatting outside broke it in few lines. btw: is it planned to make a sophisticated code formatter?

webczat avatar Dec 04 '16 21:12 webczat

The menu bar actions for organize imports, format source, etc. are not tied in to the Groovy editor. I have noticed this myself; it is on my list of items to work on but not near the top at the moment.

As far as changing the formatter implementation, that is a big job. You may need to rally some helpers to contribute towards that change.

eric-milles avatar Dec 05 '16 16:12 eric-milles

about new formatter, maybe a java formatter could be used as a base? also maybe there is some common code between formatters? not sure. About actions in the menu: it is actually confusing that it works that way, and in addition, it just prevents me from doing quick formatting of the whole project that was just moved from writing in notepad to eclipse.

webczat avatar Dec 05 '16 16:12 webczat

I looked into this and found it is quite a tough nut to crack. The menu bar actions can be overridden as long as you can act after a part (like the Package Explorer) is opened and sets the global handler. This can be done with an IPartListener. The rub is installing it early enough to catch the opening of parts on startup.

As far as the context menu items in views like the Package Explorer, those actions are not overridable via API. Some reflection tricks could be used but it is not pretty. Then each of the Groovy versions of the actions like format or organize imports needs to be made compatible with Java and Groovy since they will be called for both.

This is an area of the JDT that was not designed to be overridden. For now I'd exercise caution and use actions from the editor's context menu when possible.

eric-milles avatar Dec 20 '16 17:12 eric-milles