0

I am building a Xtext DSL and I want to embed Xbase expressions in some specific places to interpret part of my models using the Xbase interpreter, but I am not able to have method completion in the generated editor.

I reused the examples provided here: https://www.eclipse.org/Xtext/documentation/201_sevenlang_introduction.html, and manage to integrate Xbase as part of my grammar. Keyword completion proposal is working fine (i.e. do, for, while ...), but I can't find a way to have completion for Java/Xbase methods (e.g. newArrayList, or myArray.add(X)). Clarification from comments below: if I write var x = newArrayList in the editor the method is not styled in italic but I don't have any error either.

This is a sample version of the grammar I am using:

grammar org.xtext.example.common2.Common2 with org.eclipse.xtext.xbase.Xbase

generate common2 "http://www.xtext.org/example/common2/Common2"
import "http://www.eclipse.org/xtext/xbase/Xbase"

Test returns Test:
    {Test}
    'test'
    expressions+=Script
;

Script returns XBlockExpression:
    {Script}
    '{'
    (expressions+=XExpressionOrVarDeclaration ';'?)*
    '}'
;

I found out that if I change my grammar to the following one I can have the completion as expected:

grammar org.xtext.example.common2.Common2 with org.eclipse.xtext.xbase.Xbase

generate common2 "http://www.xtext.org/example/common2/Common2"
import "http://www.eclipse.org/xtext/xbase/Xbase"

Test returns XBlockExpression:
    {Test}
    'test'
    expressions+=Script
;

Script returns XBlockExpression:
    {Script}
    '{'
    (expressions+=XExpressionOrVarDeclaration ';'?)*
    '}'
;

My guess is that all the tree must be composed of instances of XExpression to enable the completion, but I don't understand why? To me Test should not be a subclass of XBlockExpression (in my real-world use case Test has additional attributes/references), but it should contain an XBlockExpression.

Is there a way to achieve this? Any help/resource to look at would be much appreciated

Note I already checked this SO question How to embed XBase expressions in an Xtext DSL, I already have xbase.lib in my build path.

zelus
  • 143
  • 8
  • are you sure you implemented the inferrer properly? – Christian Dietrich Oct 02 '19 at 09:35
  • besides that you should debug and see what is different – Christian Dietrich Oct 02 '19 at 09:36
  • Thanks for the info! I'll take a closer look to the inferrer, it's totally possible I did a mistake there – zelus Oct 02 '19 at 09:42
  • also: what kind of proposals do you miss? – Christian Dietrich Oct 02 '19 at 09:44
  • I miss all the java/xbase methods, for example `newArrayList`, but also `my_list.add(x)`. When I ask for completion proposal I basically only get `var`, `do`, `synchronized` (all the keywords). Note that if I write `var x = newArrayList` in my file the method is not styled in italic but I don't have any error either. – zelus Oct 02 '19 at 21:02
  • @ChristianDietrich as you said it was an issue with my inferrer, thanks for pointing this out! Btw is there an `JvmModelInferrer` implementation for Xbase? I searched for it in the `org.eclipse.xtext.xbase` and `org.eclipse.xtext.xbase.lib` projects but couldn't find it – zelus Oct 03 '19 at 13:21
  • not for xbase. but there is the purexbase lang https://github.com/eclipse/xtext-extras/blob/master/org.eclipse.xtext.purexbase/src/org/eclipse/xtext/purexbase/jvmmodel/PureXbaseJvmModelInferrer.xtend – Christian Dietrich Oct 06 '19 at 15:46

0 Answers0