Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Formatting after external EMF change
Formatting after external EMF change [message #1752788] Fri, 27 January 2017 05:44 Go to next message
Eclipse UserFriend
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 05:50] by Moderator

Re: Formatting after external EMF change [message #1752841 is a reply to message #1752788] Sat, 28 January 2017 06:05 Go to previous messageGo to next message
Eclipse UserFriend
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 04:01 Go to previous message
Eclipse UserFriend
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 05:44] by Moderator

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


Current Time: Sat Jul 05 15:17:58 EDT 2025

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

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

Back to the top