Search in sources :

Example 1 with IPartialEditingContentAssistContextFactory

use of org.eclipse.xtext.ui.codetemplates.ui.partialEditing.IPartialEditingContentAssistContextFactory in project xtext-eclipse by eclipse.

the class CodetemplatesProposalProvider method complete_Literal.

@Override
public void complete_Literal(EObject model, RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
    if ((mode & NESTED) != 0) {
        final TemplateData data = new TemplateData(model);
        if (data.doCreateProposals()) {
            final EvaluatedTemplate evaluatedTemplate = new EvaluatedTemplate(data.template);
            temporaryResourceProvider.useTemporaryResource(data.template.eResource().getResourceSet(), data.language, data.rule, evaluatedTemplate.getMappedString(), new IUnitOfWork.Void<XtextResource>() {

                @Override
                public void process(XtextResource resource) throws Exception {
                    IPartialEditingContentAssistContextFactory delegateFactory = languageRegistry.getPartialContentAssistContextFactory(data.language);
                    delegateFactory.initializeFor(data.rule);
                    String mappedInput = evaluatedTemplate.getMappedString();
                    int mappedOffset = Math.min(mappedInput.length(), evaluatedTemplate.getMappedOffset(context.getOffset()));
                    DummyDocument document = new DummyDocument(mappedInput);
                    DummyTextViewer dummyViewer = new DummyTextViewer(TextSelection.emptySelection(), document);
                    ContentAssistContext[] contexts = delegateFactory.create(dummyViewer, mappedOffset, resource);
                    ICompletionProposalAcceptor mappingAcceptor = new ProjectionAwareProposalAcceptor(acceptor, evaluatedTemplate);
                    createNestedProposals(contexts, context.getViewer(), mappingAcceptor, data);
                }
            });
        }
    }
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) StyledString(org.eclipse.jface.viewers.StyledString) ICompletionProposalAcceptor(org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EvaluatedTemplate(org.eclipse.xtext.ui.codetemplates.ui.evaluator.EvaluatedTemplate) IPartialEditingContentAssistContextFactory(org.eclipse.xtext.ui.codetemplates.ui.partialEditing.IPartialEditingContentAssistContextFactory) ProjectionAwareProposalAcceptor(org.eclipse.xtext.ui.codetemplates.ui.projectedEditing.ProjectionAwareProposalAcceptor)

Aggregations

StyledString (org.eclipse.jface.viewers.StyledString)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 EvaluatedTemplate (org.eclipse.xtext.ui.codetemplates.ui.evaluator.EvaluatedTemplate)1 IPartialEditingContentAssistContextFactory (org.eclipse.xtext.ui.codetemplates.ui.partialEditing.IPartialEditingContentAssistContextFactory)1 ProjectionAwareProposalAcceptor (org.eclipse.xtext.ui.codetemplates.ui.projectedEditing.ProjectionAwareProposalAcceptor)1 ICompletionProposalAcceptor (org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1