|
|
|
|
|
Re: How to order the elements in the Xtext Content Assist ? [message #1793597 is a reply to message #1793448] |
Fri, 10 August 2018 21:18 |
Parsa Pourali Messages: 210 Registered: February 2014 |
Senior Member |
|
|
Hello Christian,
I followed your hint and and applied the sample XText project (given here: https://www.eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html ).
grammar org.example.domainmodel.Domainmodel with
org.eclipse.xtext.common.Terminals
generate domainmodel "http://www.example.org/domainmodel/Domainmodel"
Domainmodel :
(elements+=Type)*;
Type:
DataType | Entity;
DataType:
'datatype' name=ID;
Entity:
'entity' name=ID ('extends' superType=[Entity])? '{'
(features+=Feature)*
'}';
Feature:
(many?='many')? name=ID ':' type=[Type];
The grammar has a domain model root element which has two sub elements: 1) datatype , 2) entity. Normally, when I use control space, the datatype element should be shown first and then the entity element should be shown in the content assist (alphabetical ordering). However, I found that if I change the code of the org.example.domainmodel.ui.contentassist.DomainmodelProposalProvider class to what is shown below I can swap the two elements (i.e., datatype and entity) in the content assist. In this method, I used a breakpoint and found that the priority of both of the elements is equal to 400 (i.e., datatype->priority=400 and entity->priority=400). So, for instance, I tried to decrease the priority of the "datatype" element and see if the two items can be reordered. The result was confusing. If I change it from 400 to 300, it does NOT work (the items will not be reordered), but if I decrease the priority to 299, then the two items are reordered.
So, now I have two questions that I'd appreciate if you could kindly clarify.
1) What is the logic behind it? why 300 doesn't work but 299 works while 300 is still less that 400?
2) I guess what I'm doing is not the best way of doing it, because here I can't check the type of the elements and can only check the string of the proposal which is fragile. Do you know of any simpler way? I checked the xbase example but that is too complex to understand :(
public class DomainmodelProposalProvider extends AbstractDomainmodelProposalProvider {
@Override
protected ConfigurableCompletionProposal doCreateProposal(String proposal, StyledString displayString, Image image,
int priority, ContentAssistContext context) {
if (proposal.equals("datatype"))
priority = 299; //300 and 400 return the same
System.out.println(displayString + " :::" + context.getCurrentModel() + ":::" + priority);
return super.doCreateProposal(proposal, displayString, image, priority, context);
}
}
Thanks for your help,
Cheers,
Parsa
|
|
|
Re: How to order the elements in the Xtext Content Assist ? [message #1793605 is a reply to message #1793597] |
Sat, 11 August 2018 05:30 |
|
I don't know. Please use a debugger
and make sure
adjustPriority/adjustKeywordPriority in ContentProposalPriorities does not interfere
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext,
ICompletionProposalAcceptor acceptor) {
ICompletionProposal proposal = createCompletionProposal(keyword.getValue(), getKeywordDisplayString(keyword),
getImage(keyword), contentAssistContext);
getPriorityHelper().adjustKeywordPriority(proposal, contentAssistContext.getPrefix());
acceptor.accept(proposal);
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Sat, 11 August 2018 05:39] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04882 seconds