Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatting after external EMF change
Formatting after external EMF change [message #1752788] Fri, 27 January 2017 10:44 Go to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
After changing the EMF object externally the formatter gets ignored.

I am using

    xtext 2.10.0,
    my own formatter extending org.eclipse.xtext.formatting2.AbstractFormatter2
    Sirius to change the emf object externally



When the formatting request is called the 'formatUndefinedHiddenRegionsOnly' is set to true.
The StringHiddenRegion 'undefined' flag is set to false by something else that is called before the formatter. This seems to be HiddenTokenSequencer with TextRegionAccessBuildingSequencer in all cases

This combination of the 2 flags will cause the formatter changes to be ignored. How can i use my formatter to apply the correct formatting to the external changes?

edit: When overriding TextRegionAccessBuildingSequencer.acceptWhitespace to NOT set StringHiddenRegion.undefined to false my own formatter is applied. I have bit of a bad feeling needing to override code here to apply my own formatter.

[Updated on: Fri, 27 January 2017 10:50]

Report message to a moderator

Re: Formatting after external EMF change [message #1752841 is a reply to message #1752788] Sat, 28 January 2017 11:05 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
Hi Koen,

passing 'true' for 'formatUndefinedHiddenRegionsOnly' tells the serializer to only format regions for which there is no pre-existing whitespace, I.d. the whitespace around the tokens that originate from your programmatically added EObject.

The StringHiddenRegion 'undefined' flag is expected to be set to false for whitespace of which both the leading and the training semantic token (i.e. not whitespace) was already there during the last parsing.

If you want the complete document to be formatted, you'll need to pass 'false' for 'formatUndefinedHiddenRegionsOnly'. You can do that by passing the proper org.eclipse.xtext.resource.SaveOptions to org.eclipse.xtext.serializer.impl.Serializer or XtextResource#save()

hth,
Moritz
Re: Formatting after external EMF change [message #1752878 is a reply to message #1752841] Mon, 30 January 2017 09:01 Go to previous message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
Thanks for your response Moritz

I want to avoid formatting the whole document because it will remove any user applied formatting.

The problem here is indeed the added whitespaces around the tokens of new additions to the emf model.
The sequencer is adding the whitespaces which prevents the formatter from being applied around the new additions.

Changing TextRegionAccessBuildingSequencer.acceptWhitespace doesnt feel safe and shouldnt be done?
If not, then i will need to reconsider if formatting the whole document is worth it.

[Updated on: Wed, 01 February 2017 10:44]

Report message to a moderator

Previous Topic:Migrating to 2.11
Next Topic:JvmTypeReference performance proxy resolution
Goto Forum:
  


Current Time: Fri Mar 29 09:45:03 GMT 2024

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

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

Back to the top