Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext templates(Xtext templates)
Xtext templates [message #1008341] Mon, 11 February 2013 23:32 Go to next message
Eclipse UserFriend
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 02:12 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Xtext templates [message #1740360 is a reply to message #1008354] Fri, 12 August 2016 05:25 Go to previous messageGo to next message
Eclipse UserFriend
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 05:29 Go to previous messageGo to next message
Eclipse UserFriend
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 05:30] by Moderator

Re: Xtext templates [message #1740363 is a reply to message #1740361] Fri, 12 August 2016 05:34 Go to previous messageGo to next message
Eclipse UserFriend
please be aware. the ID is a must must must Wink
Re: Xtext templates [message #1740365 is a reply to message #1740363] Fri, 12 August 2016 05:53 Go to previous messageGo to next message
Eclipse UserFriend
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 06:01 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Fri, 12 August 2016 06:02] by Moderator

Re: Xtext templates [message #1760358 is a reply to message #1008341] Wed, 26 April 2017 05:50 Go to previous messageGo to next message
Eclipse UserFriend
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 06:44 Go to previous message
Eclipse UserFriend
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()
Previous Topic:ERROR:The method or field .. is undefined for the type ..
Next Topic:scoping.ImportURIScopingFragment in new generator?
Goto Forum:
  


Current Time: Mon May 12 18:09:59 EDT 2025

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

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

Back to the top