How to disable auto activation of content assist [message #895217] |
Thu, 12 July 2012 03:44  |
Eclipse User |
|
|
|
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 06:26   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.51285 seconds