Differences in auto-suggest in Xtext Eclipse DSL plugins [message #1799649] |
Tue, 11 December 2018 22:58  |
Eclipse User |
|
|
|
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 #1799885 is a reply to message #1799884] |
Mon, 17 December 2018 00:32   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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 #1799897 is a reply to message #1799894] |
Mon, 17 December 2018 03:15   |
Eclipse User |
|
|
|
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 #1799908 is a reply to message #1799900] |
Mon, 17 December 2018 05:17   |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11638 seconds