Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Templates auto format
Templates auto format [message #1017737] Tue, 12 March 2013 13:13 Go to next message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi all,

I would like to have my templates formatted upon user selection (i.e. user presses enter).
In the Java preferences for templates, there is a check box "use code formatter" that does this.
Is there a way to this in XText (ex. by calling auto formatting, ...)?

Many thanks,
Nuno
Re: Templates auto format [message #1017932 is a reply to message #1017737] Tue, 12 March 2013 20:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13364
Registered: July 2009
Senior Member
Hi,

by just having a look at the code.

did you try the same a jdt does. hook into org.eclipse.xtext.ui.editor.templates.XtextTemplateContext.evaluate(Template)
and do the formatting there. e.g. by calling the serializer with formatting

include the new class by overriding
org.eclipse.xtext.ui.editor.templates.AbstractTemplateProposalProvider.doCreateTemplateContext(TemplateContextType, ContentAssistContext)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Templates auto format [message #1018240 is a reply to message #1017932] Wed, 13 March 2013 13:21 Go to previous messageGo to next message
n d is currently offline n dFriend
Messages: 11
Registered: February 2013
Junior Member
Hi,

Thank you for your reply.

I have defined MyXtextTemplateContext (which extends XtextTemplateContext) and added it by overriding the doCreateTemplateContext(...)

But I still don't see how I can format my template's text (buffer.getString()) using the serializer in the evaluate() method...

Thanks again for your help
Re: Templates auto format [message #1018247 is a reply to message #1018240] Wed, 13 March 2013 13:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13364
Registered: July 2009
Senior Member
I just gave you a starting hint. Maybe simply parse and reserialze
the snippet?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Templates auto format [message #1018248 is a reply to message #1018240] Wed, 13 March 2013 13:39 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13364
Registered: July 2009
Senior Member
Maybe you can file an enhancement for that. Or simply preformat the
templates in the editor

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Any way to access the name of a reference in the ScopeProvider?
Next Topic:Referring to existing Java methods using Xbase
Goto Forum:
  


Current Time: Wed Feb 26 11:39:09 GMT 2020

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

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

Back to the top