Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext templates(Xtext templates)
Xtext templates [message #1008341] Tue, 12 February 2013 04:32 Go to next message
Girish Kumar is currently offline Girish KumarFriend
Messages: 48
Registered: May 2011
Member
Hi All,

I wanted to create template for content assist.

The documentation says : you need to create a folder named templates and add templates.xml inside it.

I have created templates.xml by exporting it from the runtime preference page.

The same i added into templates folder of ui plugin.

But it is not working..

Please let me know, i have done anything wrong ??

As a matter of fact, I have also added template folder to exported in build.properties.

Regards
Girish
Re: Xtext templates [message #1008354 is a reply to message #1008341] Tue, 12 February 2013 07:12 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the documentation says a bit more than this!
Quote:
It is best practice to edit the templates in the preferences page, export them into the templates.xml-file and put this one into the templates folder of your UI-plug-in. However, these templates will not be visible by default. To fix it, you have to manually edit the xml-file and insert an id attribute for each template element. Note that the attribute name is case sensitive. As always in eclipse plug-in development, if the folder templates did not exist before, you have to add it to the bin.includes in your build.properties.


Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Xtext templates [message #1740360 is a reply to message #1008354] Fri, 12 August 2016 09:25 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Hi,
I did all you mentioned but it does not work either.
Re: Xtext templates [message #1740361 is a reply to message #1740360] Fri, 12 August 2016 09:29 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
In your "lang.ui" project:
* create the folder "templates"
* create the file "templates/templates.xml"
* edit the file with something similar to:
<?xml version="1.0" encoding="UTF-8" ?> 
<templates>
	<template
	    name="def"
	    description="public method"
	    id="def"
	    context="io.sarl.lang.SARL.Member"
	    enabled="true"
	    autoinsert="false">def ${name}(${params}) {
		${cursor}
	}</template>
	<template
	    name="protecteddef"
	    description="protected method"
	    id="protected_def"
	    context="io.sarl.lang.SARL.Member"
	    enabled="true"
	    autoinsert="false">protected def ${name}(${params}) {
		${cursor}
	}</template>
</templates>

[Updated on: Fri, 12 August 2016 09:30]

Report message to a moderator

Re: Xtext templates [message #1740363 is a reply to message #1740361] Fri, 12 August 2016 09:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
please be aware. the ID is a must must must Wink

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext templates [message #1740365 is a reply to message #1740363] Fri, 12 August 2016 09:53 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Hi,
I have this templates.xml it resides in the templates folder in the ui project of my plugin and it is enabled in the build section for binary builds.
if I run my plugin in a runtime eclipse the templates are not loaded.
I cannot see my mistake:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="keyword &quot;.&quot; &quot;:&quot;"
		enabled="true" name="keyworddot" id="keyworddot">keyword "." ":" {
			format dot {
			nospace around
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="keyword &quot;,&quot; " enabled="true"
		name="keywordkomma" id="keywordkomma">keyword "," {
			format komma {
			nospace before
			space " " after
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="keyword &quot;;&quot;" enabled="true"
		name="keywordsemicolon" id="keywordsemicolon">keyword ";" {
			format semicolon {
			nospace before
			linewrap(2,0,1) after
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="format linewrapAround(2,1,1)" enabled="true"
		name="linewrapAround" id="linewrapAround">format linewrapAround linewrap (2, 1,1)
		around</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="pair &quot;(&quot; &quot;)&quot; &quot;[&quot; &quot;]&quot;"
		enabled="true" name="pair()"id="pairparenteses">pair "(" ")" "[" "]" {
			format openParentesis {
			nospace around
			}
			format closingParentesis {
			nospace before
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatterDefinition"
		deleted="false" description="pair &quot;{&quot; &quot;}&quot; "
		enabled="true" name="pair{}" id="pairbaces">pair "{" "}" {
			format openBrace {
			space " " before
			linewrap(2, 0, 0) after
			indent after
			}
			format closingBrace {
			linewrap(2, 1, 1) before
			deindent before
			}
		}
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use closingBrace" enabled="true"
		name="useclosingBrace" id="useclosingBrace">use closingBrace</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use closingParentesis" enabled="true"
		name="useclosingParentesis"id="useclosingParentesis">use closingParentesis</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use dot" enabled="true" name="usedot" id="usedot">use dot
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use komma" enabled="true" name="usekomma"id="usekomma">use komma
	</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use semicolon" enabled="true" name="useksemicolon"id="useksemicolon">use
		semicolon</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use linewrapAround" enabled="true"
		name="uselinewrapAround"id="uselinewrapAround">use linewrapAround ${Max_Min_Default}</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use openBrace" enabled="true" name="useopenBrace"id="useopenBrace">use
		openBrace</template>
	<template autoinsert="true"
		context="de.mdsd.xtext.formatter2.model.FormatterModel.FormatDefinition"
		deleted="false" description="use openParentesis" enabled="true"
		name="useopenParentesis"id="useopenParentesis">use openParentesis</template>
</templates>
Re: Xtext templates [message #1740366 is a reply to message #1740365] Fri, 12 August 2016 10:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you try the following

(1) create a bunch of templates with the editor in eclipse
(1b) test them in eclipse
(2) export them
(3) remove those created in eclipse
(4) add the exportted to your template.xml
(5) add the missing ids
(6) start eclipse


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 12 August 2016 10:02]

Report message to a moderator

Re: Xtext templates [message #1760358 is a reply to message #1008341] Wed, 26 April 2017 09:50 Go to previous messageGo to next message
Paul Harrison is currently offline Paul HarrisonFriend
Messages: 2
Registered: January 2016
Junior Member
I still have exactly this problem with Xtend 2.11 - can anyone point me to where the templates are loaded so that I can look in the debugger to try to see what might still be wrong.
Re: Xtext templates [message #1760361 is a reply to message #1760358] Wed, 26 April 2017 10:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
my list missed one point: make sure the templates.xml is mentioned in build.properties
besides this the code for loading it is in org.eclipse.xtext.ui.editor.templates.XtextTemplateStore.loadContributedTemplates()


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:ERROR:The method or field .. is undefined for the type ..
Next Topic:scoping.ImportURIScopingFragment in new generator?
Goto Forum:
  


Current Time: Thu Mar 28 22:56:35 GMT 2024

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

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

Back to the top