Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to order the elements in the Xtext Content Assist ?
How to order the elements in the Xtext Content Assist ? [message #1793410] Tue, 07 August 2018 17:49 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Hello,

Can you please help me on ordering the elements in the content assist? I am trying to sort the elements by their grammar type. For instance, first display all the elements that are from type A, then show all with the type B and etc...

Apparently, I have to work with the DefaultTemplateProposalProvider class but have no idea on how to use it ? should I just create a new class in my Xtext project and extend the DefaultTemplateProposalProvider class?

I'd appreciate it if you could kindly help me with this.

Thanks,
Parsa
Re: How to order the elements in the Xtext Content Assist ? [message #1793411 is a reply to message #1793410] Tue, 07 August 2018 17:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
hi, i am not sure if i get you

- template proposals and normal proposals (MyDslProposalProvider) are different things.
- proposals are sorted by Prio. ContentProposalPriorities / org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal.priority


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to order the elements in the Xtext Content Assist ? [message #1793412 is a reply to message #1793411] Tue, 07 August 2018 18:08 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Hi Christian,

Thanks for your reply. So, should I work with the ContentProposalPriorities? Should I use an extension point to extend it ? How can I impose such priorities? Can you please explain a little bit more? I mean, should I modify an existing class or should I create a new class or extension point?

Thanks,
Parsa
Re: How to order the elements in the Xtext Content Assist ? [message #1793414 is a reply to message #1793412] Tue, 07 August 2018 18:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
please have a look at search results and existing customizations for that. (e.g. XbaseContentProposalPriorities)
i dont have any complete example at hand - especially if you dont have any requirements
=> i recommend you to use a debugger and see what happens

see https://www.eclipse.org/forums/index.php/t/1081898/ too


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to order the elements in the Xtext Content Assist ? [message #1793448 is a reply to message #1793414] Wed, 08 August 2018 13:34 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Thanks Christian for the hint.

Regards,
Parsa
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 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
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 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
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);
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 11 August 2018 05:39]

Report message to a moderator

Previous Topic:How to multi selection in the xtext Content Assist
Next Topic:Using arrays Arrays and DotNotation in Expressions
Goto Forum:
  


Current Time: Sun Sep 23 17:55:05 GMT 2018

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

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

Back to the top