Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Differences in auto-suggest in Xtext Eclipse DSL plugins(Why does auto-suggest differ with the grammar declarations?)
Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799649] Tue, 11 December 2018 22:58 Go to next message
Eclipse UserFriend
Hi,
I'm writing a DSL as an Eclipse plugin using Xtext. I just realized that if I used a reference to a keyword instead of directly stating it within single quotes, it won't be suggested in the runtime. For instance: -

Domainmodel:
	(elements+=MainElement)*
;

MainElement:
	'projection' name=ID ';'
;


The above code, in the runtime, will suggest me both 'projection' keyword and 'name'. However, if I used the below code instead, it won't provide auto-suggestion, but will only identify that it is a correct syntax: -

Domainmodel:
	(elements+=MainElement)*
;

MainElement:
	KEYWORD_projection name=projectionName ';'
;

KEYWORD_projection:
        'projection'
;

projectionName:
        identifier
;

identifier:
        ID | 'All'
;


Could anyone kindly explain the reason for this and whether I could apply auto suggestion for codes written in the 2nd method?
Thank you!
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799655 is a reply to message #1799649] Wed, 12 December 2018 00:41 Go to previous messageGo to next message
Eclipse UserFriend
You have to implement content assist for datatype rules yourself by overriding the corresponding complete method in your propoosalprovidee
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799726 is a reply to message #1799655] Wed, 12 December 2018 22:35 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Thanks for the reply. I found out that by implementing this (below) I can achieve my goal: -

Domainmodel:
	(elements+=MainElement)*
;

MainElement:
	keyword=KEYWORD_projection name=projectionName ';'
;

KEYWORD_projection:
        key='projection'
;

projectionName:
        identifiers=identifier
;

identifier:
        ids=ID | 'All'
;

[Updated on: Wed, 12 December 2018 22:36] by Moderator

Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799730 is a reply to message #1799726] Thu, 13 December 2018 01:33 Go to previous messageGo to next message
Eclipse UserFriend
This creates a different ast. You no longer have a datatype rule but a parser rule right now
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799754 is a reply to message #1799730] Thu, 13 December 2018 04:48 Go to previous messageGo to next message
Eclipse UserFriend
Will that make a significant change?
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799756 is a reply to message #1799754] Thu, 13 December 2018 05:00 Go to previous messageGo to next message
Eclipse UserFriend
the ast/metamodel will be significantly different. have a look at the KEYWORD_projection class
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799884 is a reply to message #1799756] Sun, 16 December 2018 23:11 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

Is it possible for you to provide a simple example on how I could implement content assistance to the below code snippet? I went through blog posts and issues related to content assist, but I would be able to grasp the idea better if there was a simple example.

Domainmodel:
	elements+=projection_name

projection_name
   : KEYWORD_projection   projection_name_model_name   SEMICOLON
   ;

projection_name_model_name
   : identifier2
   ;

KEYWORD_projection
   : ( 'projection' )
   ;

SEMICOLON
   :  ';'
   ;

identifier2
   : ID
;


What I want to implement with this code is when I press Ctrl+space each time, each of the 3 parts in projection_name should be suggested in the order given in the rule.

Thank You!

[Updated on: Sun, 16 December 2018 23:13] by Moderator

Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799885 is a reply to message #1799884] Mon, 17 December 2018 00:32 Go to previous messageGo to next message
Eclipse UserFriend
I figured out the below code so far by going through different blog posts and tutorials:

class MyDslProposalProvider extends AbstractMyDslProposalProvider {	
	@Inject
	private MyDslGrammarAccess ga;
	
	override complete_projection_name(EObject model, RuleCall ruleCall, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
			super.complete_projection_name(model, ruleCall, context, acceptor)
			val ICompletionProposal proposal = createCompletionProposal("projection", "projection", getImage(ga.projection_nameRule), context);
			getPriorityHelper().adjustKeywordPriority(proposal, context.getPrefix());
			acceptor.accept(proposal)
		}
	
}


Now 'projection' is suggested at the beginning. Could you please tell me what 'getImage(ga.projection_nameRule)' mean?

[Updated on: Mon, 17 December 2018 01:03] by Moderator

Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799887 is a reply to message #1799885] Mon, 17 December 2018 01:08 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I tried implementing the same for 'projection_name_model_name' as well using the below code:

@Inject
	private MyDslGrammarAccess ga;
	
	override complete_projection_name(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// subclasses may override
		super.complete_projection_name(model, ruleCall, context, acceptor)
		val ICompletionProposal proposal = createCompletionProposal("projection", "projection", getImage(ga.projection_nameRule), context);
		//getPriorityHelper().adjustKeywordPriority(proposal, context.getPrefix());
		acceptor.accept(proposal)
	}
	
	override complete_projection_name_model_name(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// subclasses may override
		super.complete_projection_name_model_name(model, ruleCall, context, acceptor)
		val ICompletionProposal proposal = createCompletionProposal("NewProjection", "NewProjection", getImage(ga.projection_name_model_nameRule), context);
		//getPriorityHelper().adjustKeywordPriority(proposal, context.getPrefix());
		acceptor.accept(proposal)
	}


However, only the 'projection' keyword is suggested and 'NewProjection' is not.
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799894 is a reply to message #1799887] Mon, 17 December 2018 03:07 Go to previous messageGo to next message
Eclipse UserFriend
is there any reasons you do such bad grammars with not making use of assignments and moving keywords to separate rules?
this is a usecase that is not usual and may have its problems
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799897 is a reply to message #1799894] Mon, 17 December 2018 03:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I know it must be quite confusing to you why I'm having separate rules for simple keywords whereas I could just declare the keyword directly. But I have a somewhat long .g4 file given to me, which I should convert to Xtext. I'm trying to keep its rules the way they are as much as possible to avoid the possibility to miss important rules entangled within.
Could you kindly tell me why the .xtend file does not suggest the second word in runtime?

Quote:

@Inject
private MyDslGrammarAccess ga;

override complete_projection_name(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
super.complete_projection_name(model, ruleCall, context, acceptor)
val ICompletionProposal proposal = createCompletionProposal("projection", "projection", getImage(ga.projection_nameRule), context);
//getPriorityHelper().adjustKeywordPriority(proposal, context.getPrefix());
acceptor.accept(proposal)
}

override complete_projection_name_model_name(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
super.complete_projection_name_model_name(model, ruleCall, context, acceptor)
val ICompletionProposal proposal = createCompletionProposal("NewProjection", "NewProjection", getImage(ga.projection_name_model_nameRule), context);
//getPriorityHelper().adjustKeywordPriority(proposal, context.getPrefix());
acceptor.accept(proposal)
}

Thank you!

[Updated on: Mon, 17 December 2018 03:16] by Moderator

Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799898 is a reply to message #1799897] Mon, 17 December 2018 03:28 Go to previous messageGo to next message
Eclipse UserFriend
the main problem ist that xtext may call the proposal rules only at the places of an assignment
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799899 is a reply to message #1799898] Mon, 17 December 2018 03:33 Go to previous messageGo to next message
Eclipse UserFriend
and having no assignments may give you an unusable ast
e.g.

Domainmodel:
elements+=projection_name
;
projection_name
: KEYWORD_projection name=projection_name_model_name SEMICOLON
;

will solve your problem
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799900 is a reply to message #1799899] Mon, 17 December 2018 03:49 Go to previous messageGo to next message
Eclipse UserFriend
The 'name=projection_name_model_name' assignment made everything work fine. Thank you very much Christian!

[Updated on: Mon, 17 December 2018 03:49] by Moderator

Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799908 is a reply to message #1799900] Mon, 17 December 2018 05:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

I thought of trying out what you suggested and wrote a much simpler grammar. However, now I have another problem,

Domainmodel:
	elements+=projection_name elements+=projection_component (elements+=MainElement)*
;

MainElement:
	capability | category 
;
projection_name
   : 'projection' name=projection_name_model_name ';'
   ;

projection_name_model_name
   : ModelName=ID
   ;

projection_component
   : 'component' name=projection_component_component_name ';'
   ;

projection_component_component_name
   : ComponentName=ID
   ;

capability
   : 'capability' ( 'Online' | 'Offline' ) ';'
   ;

category
   : 'category' ( 'Integration' | 'ExternalB2B' | 'Users' ) ';'
   ;


Here, I get suggestion for 'projection' and 'component', but not for 'capability' and 'category'. Even more, the latter two rules are shown in blue colour text.
It must be related with those two not having assignments. I know this because I tried out changing the rule 'capability' as follows: -

capability
   : x='capability' ( 'Online' | 'Offline' ) ';'
   ;


OR

capability
   : {capability} 'capability' ( 'Online' | 'Offline' ) ';'
   ;

For either of the above changes, 'capability' was listed in suggestions. Is there a way to handle this without having to add assignments and creating objects, or is it the only way? If it is the only way, which option is the better (assignment or object creation)?

Regards!

[Updated on: Mon, 17 December 2018 06:15] by Moderator

Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799914 is a reply to message #1799908] Mon, 17 December 2018 06:52 Go to previous messageGo to next message
Eclipse UserFriend
your grammar makes no sense
you need that.
otherwise you cannot do the (elements+=MainElement)
i again dont understand: if you dont assign anything you will not get any useful ast.
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799955 is a reply to message #1799914] Mon, 17 December 2018 21:34 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Could you please let me know whether the following modification is correct according to you?

Domainmodel:
	elements+=projection_name elements+=projection_component (elements+=MainElement)*
;

MainElement:
	capability | category 
;
projection_name
   : key='projection' projection_name_model_name=ID punc=';'
   ;

projection_component
   : key='component' projection_component_component_name=ID punc=';'
   ;

capability
   : key='capability' ( alt='Online' | alt='Offline' ) ';'
   ;

category
   : key='category' ( alt='Integration' | alt='ExternalB2B' | alt='Users' ) punc=';'
   ;
Re: Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799963 is a reply to message #1799955] Tue, 18 December 2018 01:21 Go to previous message
Eclipse UserFriend
Well for pure keywords you don't need assignments
Thus

key='category'
And
punc=';'

Should not be assignments since these are keywords that don't transport any information
Previous Topic:Adding Content Assist to Xtext Gradle Project
Next Topic:How to create complete code suggestions in Xtext Eclipse Plugin?
Goto Forum:
  


Current Time: Fri Jun 20 19:41:26 EDT 2025

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

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

Back to the top