Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to disable auto activation of content assist
How to disable auto activation of content assist [message #895217] Thu, 12 July 2012 07:44 Go to next message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member
Hi,

I need to disable the auto activation of content assist in certain scenarios. Could we customize the auto activation to work only in selected scenarios? For example, I do not want the auto content assist in case of comments. Is there a way to achieve this?

Thanks in advance for any help,
Latha
Re: How to disable auto activation of content assist [message #895269 is a reply to message #895217] Thu, 12 July 2012 10:26 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 715
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Hi Latha,

you can override MyDSLProposalProvider#createProposals() like this:
public class DomainmodelProposalProvider extends AbstractDomainmodelProposalProvider {
	@Inject
	private DomainmodelGrammarAccess ga;
	
	@Override
	public void createProposals(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// suppress content assist in multi-line comments
		if (context.getCurrentNode().getGrammarElement()==ga.getML_COMMENTRule())
			return;
		
		super.createProposals(context, acceptor);
	}
}



This would still show template proposals, so you would have to subclass DefaultTemplateProposalProvider, bind your class in the UI module and override createTemplates() similar.

Alternatively you could also sublcass CompletionProposalComputer and override exec() and decide similar that proposals should not be created in the context of comments.


	public ICompletionProposal[] exec(XtextResource resource) throws Exception {
		ICompletionProposalAcceptor proposalAcceptor = state.decorateAcceptor((ICompletionProposalAcceptor)this);
		ContentAssistContext[] contexts = state.getContextFactory().create(viewer, offset, resource);
		for (ContentAssistContext context: contexts) {
			if (proposalAcceptor.canAcceptMoreProposals() && context.getCurrentNode().getGrammarElement()==ga.getML_COMMENTRule())
				state.getContentProposalProvider().createProposals(context, proposalAcceptor);
		}
		ITemplateAcceptor templateAcceptor = state.decorateAcceptor((ITemplateAcceptor) this);
		for (ContentAssistContext context: contexts) {
			if (templateAcceptor.canAcceptMoreTemplates() && context.getCurrentNode().getGrammarElement()==ga.getML_COMMENTRule())
				state.getTemplateProposalProvider().createTemplates(context, templateAcceptor);
			
		}
		return proposals.toArray(new ICompletionProposal[proposals.size()]);
	}



Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: How to disable auto activation of content assist [message #895458 is a reply to message #895269] Fri, 13 July 2012 06:04 Go to previous message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member
Hi Karsten,

Thanks for your reply! Smile That helped me.
Previous Topic:Cross reference is being activated without an import, why ?
Next Topic:Xtext 2.3 Static Properties
Goto Forum:
  


Current Time: Thu Feb 20 12:16:42 GMT 2020

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

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

Back to the top