Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to format xtext resource on save
how to format xtext resource on save [message #1693387] Thu, 23 April 2015 17:15 Go to next message
Richard Ral is currently offline Richard RalFriend
Messages: 6
Registered: December 2013
Junior Member
I am trying to format (pretty print) my dsl text on saving xtext resource.
I have already set save options to format:
SaveOptions.Builder options = SaveOptions.newBuilder();
options.format();
options.noValidation();
xtextResource.save(options.getOptions().toOptionsMap());

And I have already defined formatting class:
class MyModelFormatter extends AbstractFormatter2 {
@Inject extension MyModelGrammarAccess

def dispatch void format(MyModel myModel, extension IFormattableDocument document) {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
for (PackageDeclaration packages : myModel.getPackages()) {
format(packages, document);
packages.append[newLine]
}
}
....
}

The problem is that when I am saving xtext resource it isn't being formatted at all.
What do I miss?
Re: how to format xtext resource on save [message #1693395 is a reply to message #1693387] Thu, 23 April 2015 17:49 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi,

there i a bug in Xtext <= 2.8.2 that the serializer uses the old formatter only.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=453440


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Nested Expressions / Recursion
Next Topic:Antlr grammar for content assist
Goto Forum:
  


Current Time: Sun Apr 18 09:42:07 GMT 2021

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

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

Back to the top