|"Partial" Formatting [message #629509]
||Tue, 28 September 2010 10:22
Registered: April 2010
I have a problem with the way the formatting of a region is handled in org.eclipse.xtext.formatting.impl.NodeModelStreamer. When I try to format a part of the source which should be indented, it is not. Naturally, I thought this was due to my implementation of the ITokenStream written to, but reading the code in NodeModelStreamer, I just can't figure out how this might actually work.
What I figure is the following: when searching for the correct leaf nodes to base the formatting on in getLeafs, the first leaf found will be the first one formatted and also the first one to be passed to the ITokenStream doing the actual formatting. And as this is the place where the information necessary to calculate the necessary indentation, I don't see how this information might be deduced.
Imho, the easiest way to do "region" formatting would be to format the source from the beginning, reset the buffer in ITokenStream (introduce e.g. a reset method) when the offset of the first "semantic" node to be written is reached and then just continuing until the length to be formatting is covered. Wouldn't that work?
Still better, the whitespace between the last "semantic" node not written and the first one written could be formatted according to the rules, so that the "maximum" rule for linewrap locators is preserved (imagine we have a rule saying we need two linewraps before the first "semantic" node formatted, there are already two empty lines before the region to format, but none of this whitespace is selected, two lines are still inserted)...
Powered by FUDForum
. Page generated in 0.01465 seconds