Community
Participate
Working Groups
In some cases (e.g. column layouts) there is no better way of formatting then the user does himself. Thus it should be possible to explicitly ignore sections from formatting and take the original input format as output.
I encountered the same requirement. This Hack worked in my case: 1. Extend ...formatting.impl.FormattingConfig and introduce public class PreserveSpaceLocator extends SpaceLocator {} 2. Patch FormattingConfigBasedStream.line.getSpacesStr ... for (ElementLocator leadingLocator : entry.leadingLocators) /** PATCH - START- */ if (leadingLocator instanceof PreserveSpaceLocator) { return entry.leadingWS; } else /** PATCH - END - */ if (leadingLocator instanceof SpaceLocator) { ...
There is still no explicit support for this, but it's easy to implement with the new formatter: When creating the FormattingRequest, scan the TextRegionAccess for those tokens that should enable/disable formatting and based on this configure the text ranges in org.eclipse.xtext.formatting2.FormatterRequest.getRegions(). I think that's good enough to close this ticket. Improved support such as dedicated API or a user interface should be treated by new tickets in https://github.com/eclipse/xtext-core/issues