OrenIshShalom
OrenIshShalom

Reputation: 7162

xtext and ace web editor code generation failed communication

I'm using the Invoking Services section from xtext web editor support with ace:

var editor = xtext.createEditor();
$("#save-button").click(function() {
    // editor.xtextServices.saveResource();
    editor.xtextServices.generate();
});

I'm using the default Greeting grammar, and want to enable the default code generation:

// filename: <MyLovaelyDslName>Generator.xtend

class Phase0Generator extends AbstractGenerator {

    override void doGenerate(
        Resource resource,
        IFileSystemAccess2 fsa,
        IGeneratorContext context
    ) {
        fsa.generateFile('greetings.txt', 'People to greet: ' + 
            resource.allContents
                .filter(Greeting)
                .map[name]
                .join(', '))
    }
}

When I inspect the GET requests in the browser I see (10 requests like):

GET http://localhost:8080/xtext-service/generate?resource=67e22793.veri&requiredStateId=-7ffffff4 404 (Not Found)

followed by:

Xtext service 'generate' failed: Xtext service request failed after 10 attempts.
xtext-ace.js:1114 Xtext service 'generate' failed: Not Found

What am I missing in the ace-xtext communication? (Syntax highlights + custom validations I wrote work perfect)

EDIT

I found this part in the documentation:

The usual way to include the Xtext servlet in a server application is to create a subclass of XtextServlet, override init() and destroy() to manage the runtime resources, and add a WebServlet annotation with urlPatterns = "/xtext-service/*" as parameter. See MyXtextServlet for an example

When I add override doGet in this subclass, I manage to intercept all requests and can delegate all non-generate requests to the super. But still, I don't have a clue how to get to the generate relevant method:

@WebServlet(name = "XtextServices", urlPatterns = "/xtext-service/*")
public class Phase0Servlet extends XtextServlet {
    public void init() throws ServletException { /* ... */ }
    public void destroy() { /* ... */ }

    @Override
    protected void doGet(
        HttpServletRequest req,
        HttpServletResponse response
    ) throws ServletException, IOException
    {
        var service = getService(req);
        var serviceType = <omitted>.getParameter("serviceType");
        if (serviceType.equals("generate")) { /* ... */ }
        else                                { /* ... */ }
    }
}

Upvotes: 1

Views: 133

Answers (0)

Related Questions