Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialization: Indent missing at start of semantic modification
Serialization: Indent missing at start of semantic modification [message #1746528] Mon, 31 October 2016 17:17 Go to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1497
Registered: July 2009
Senior Member
This looks like room for improvement in the serializer, but let me check with you before filing a bug:

I have a model of this structure
module E {
    entity a {}

I have a quick fix that should add more entities, which is implemented as a semantic modification. The result of applying the quick fix is:
module E {
    entity a {}
entity b {}
    entity c {}

Problem: entity b is not properly indented. Formatter seems to be OK as Ctrl-Shift-F corrects the problem.

I could narrow it down to problematic interaction between HiddenTokenSequencer and FormattingConfigBasedStream:
When processing the '}' right before the insertion point for the new entities, we create a "preservedWS" containing just "\n".
Later during FormattingConfigBasedStream.Line.getSpacesStr(LineEntry, boolean), this preservedWS prevents computation of correct WS including indentation.

I could experimentally fix this inside HiddenTokenSequencer.getHiddenNodesBetween(): at the end of the (to == null) branch, I simply remove any trailing whitespace from out (still ensuring that trailing comments are correctly preserved incl. previous whitespace).
			for (int i = out.size() - 1; i >= 0; i--) {
				if (!tokenUtil.isWhitespaceNode(out.get(i)))

This seems to ensure that at the transition from old to new elements (the latter not having any nodes, yet) we don't spill preservedWS into the next (yet unformatted) element.

Does this make sense wrt the design of serialization? If so, are bugs in bugzilla still accepted (I don't have a github account)?


Re: Serialization: Indent missing at start of semantic modification [message #1746562 is a reply to message #1746528] Mon, 31 October 2016 21:58 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11062
Registered: July 2009
Senior Member
i can not reproduce this with a simple unit test (with 2.11).

	"module" name=ID "{"
	'entity' name=ID '{''}';

import org.eclipse.xtext.serializer.ISerializer
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Test
import org.junit.runner.RunWith
import org.xtext.example.mydsl1.myDsl.Module
import org.xtext.example.mydsl1.myDsl.MyDslFactory

class DummyTest {
	extension ParseHelper<Module> 
	extension ISerializer
	def void testIt() {
		val m =
		module E {
		    entity a {}
		m.entities += MyDslFactory.eINSTANCE.createEntity=>[name="b"] 
		m.entities += MyDslFactory.eINSTANCE.createEntity=>[name="c"] 

class MyDslFormatter extends AbstractFormatter2 {
	@Inject extension MyDslGrammarAccess

	def dispatch void format(Module module, extension IFormattableDocument document) {
		for (Entity entity : module.getEntities()) {
	def dispatch void format(Entity e, extension IFormattableDocument document) {

but i can reproduce it from a quickfix

can you please file a ticket? (bugzilla is ok although github issue is prefered)

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :

[Updated on: Mon, 31 October 2016 22:20]

Report message to a moderator

Previous Topic:dynamic template proposals in xtext revisited
Next Topic:Debugging non-deterministic serialization failure
Goto Forum:

Current Time: Thu Aug 17 19:41:21 GMT 2017

Powered by FUDForum. Page generated in 0.05476 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software