Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Web editor unable to generate with inferrer
Web editor unable to generate with inferrer [message #1729495] Thu, 14 April 2016 17:26 Go to next message
Stirling Poon is currently offline Stirling PoonFriend
Messages: 3
Registered: April 2016
Junior Member
As my grammer uses XBase, I am using a JvmModelInferrer which successfully converts my DSL into Java code in Eclipse. However in the web editor, calling generate() seems to require a generator. I have tried to create a generator that hooks into the inferrer by:

class MyRuntimeModule extends AbstractMydslRuntimeModule {
	override bindIGenerator() {
		return JvmModelGenerator
	}
}


However I still get the error "Xtext service 'generate' failed: The requested generator artifact was not found." in the web editor. How can I create a generator, or make the web editor use my inferrer?

Thanks!
Re: Web editor unable to generate with inferrer [message #1729553 is a reply to message #1729495] Fri, 15 April 2016 12:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

this generator is bound by default - it is not the problem.
the problem is the impl of the generator service.
it asumes the generated file to have a certain name.
thus it wont wont this way.

have a look at

org.eclipse.xtext.web.server.generator.GeneratorService.getArtifact(XtextWebDocumentAccess, String)

with

public static val DEFAULT_ARTIFACT = IFileSystemAccess.DEFAULT_OUTPUT + '/DEFAULT_ARTIFACT'


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Web editor unable to generate with inferrer [message #1729567 is a reply to message #1729495] Fri, 15 April 2016 14:33 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You have to pass a 'artifactId' parameter to the generate funtion:

xtextEditor.xtextServices.generate({"artifactId":"foo"})


HTH,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Web editor unable to generate with inferrer [message #1729572 is a reply to message #1729567] Fri, 15 April 2016 14:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
It actually is artifact and not artifactId on client side

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Web editor unable to generate with inferrer [message #1729578 is a reply to message #1729572] Fri, 15 April 2016 15:33 Go to previous messageGo to next message
Stirling Poon is currently offline Stirling PoonFriend
Messages: 3
Registered: April 2016
Junior Member
Thanks Karsten and Christian for your quick responses, the JavaScript is xtextServices.generate({"artifactId":"foo"}) while the form data in the POST request sent is artifact: foo.
In my DSL, each resource can generate multiple artifacts, with the ID of each artifact generated based on the contents of the file. Without having the parse my DSL client-side, is there a way to get a list of all artifact IDs generated from the resource, so that I can call generate() for each ID?
Re: Web editor unable to generate with inferrer [message #1729581 is a reply to message #1729578] Fri, 15 April 2016 16:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes and no. what about having your own service

class MyDslWebModule extends AbstractMyDslWebModule {
	
	def Class<? extends XtextServiceDispatcher> bindXtextServiceDispatcher() {
		return MyDslXtextServiceDispatcher
	}
}

import com.google.inject.Inject
import javax.inject.Singleton
import org.eclipse.xtext.util.internal.Log
import org.eclipse.xtext.web.server.IServiceContext
import org.eclipse.xtext.web.server.InvalidRequestException
import org.eclipse.xtext.web.server.XtextServiceDispatcher
import org.eclipse.xtext.web.server.generator.GeneratorService

@Log
@Singleton
class MyDslXtextServiceDispatcher extends XtextServiceDispatcher{
	
	@Inject
  	private GeneratorService generatorService;
	
	override protected createServiceDescriptor(String serviceType, IServiceContext context) {
		if (serviceType == "generate-all") {
			return getGeneratorAllService(context)
		}
		super.createServiceDescriptor(serviceType, context)
	}
	
	protected def getGeneratorAllService(IServiceContext context)
			throws InvalidRequestException {
		val document = getDocumentAccess(context)
		new ServiceDescriptor => [
			service = [
				try {
					generatorService.getResult(document)
				} catch (Throwable throwable) {
					handleError(throwable)
				}
			]
		]
	}
	
}
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="en-us">
	<title>Example Web Editor</title>
	<link rel="stylesheet" type="text/css" href="xtext/2.9.2/xtext-ace.css"/>
	<link rel="stylesheet" type="text/css" href="style.css"/>
	<script src="webjars/requirejs/2.1.20/require.min.js"></script>
	<script type="text/javascript">
		var baseUrl = window.location.pathname;
		var fileIndex = baseUrl.indexOf("index.html");
		if (fileIndex > 0)
			baseUrl = baseUrl.slice(0, fileIndex);
		require.config({
			baseUrl: baseUrl,
			paths: {
				"jquery": "webjars/jquery/2.1.4/jquery.min",
				"ace/ext/language_tools": "webjars/ace/1.2.0/src/ext-language_tools",
				"xtext/xtext-ace": "xtext/2.9.2/xtext-ace"
			}
		});
		require(["webjars/ace/1.2.0/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				xtext.createEditor({
					baseUrl: baseUrl,
					syntaxDefinition: "xtext-resources/generated/mode-mydsl7"
				});
				
				jQuery('#generate-button').bind("click", function(e){
					
					jQuery('#generator-result').html('<iframe src="http://' + location.host + '/xtext-service/generate-all?resource=example1.mydsl7"></iframe>');
					e.preventDefault();
				});
				
			});
		});
	</script>
</head>
<body>

<div class="container">
	<div class="header">
		<h1>Example MyDsl Web Editor2</h1>
	</div>
	<div class="content">
		<div id="xtext-editor" data-editor-xtext-lang="mydsl7" data-editor-resource-id="example1.mydsl7"></div>
	</div>
	<div class="button-wrapper">
		<button id="generate-button" value="Generate" title="Generate">Generate</button>
		<div id="generator-result">
			Result
		</div>
	</div>
</div>

</body>
</html>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Web editor unable to generate with inferrer [message #1729643 is a reply to message #1729581] Sat, 16 April 2016 18:11 Go to previous message
Stirling Poon is currently offline Stirling PoonFriend
Messages: 3
Registered: April 2016
Junior Member
This works perfectly, thanks Christian!
Previous Topic:How to exclude certain Xtext files from the indexing process
Next Topic:Re: [XCore] The Body of the method
Goto Forum:
  


Current Time: Fri Apr 19 19:06:49 GMT 2024

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

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

Back to the top