| Summary: | [formatter] Allow to disable autoformat locally | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Karsten Thoms <karsten.thoms> |
| Component: | Xtext Backlog | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | boris.holzer, moritz.eysholdt |
| Version: | 2.0.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
|
Description
Karsten Thoms
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 |