Search in sources :

Example 6 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.

the class CodetemplatesProposalProvider method completeNestedAssignment.

public void completeNestedAssignment(Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) {
    String proposalText = "${" + assignment.getFeature() + "}";
    StyledString displayText;
    if (assignment.getTerminal() instanceof RuleCall) {
        RuleCall ruleCall = (RuleCall) assignment.getTerminal();
        AbstractRule calledRule = ruleCall.getRule();
        displayText = new StyledString("${", StyledString.DECORATIONS_STYLER).append(assignment.getFeature(), null).append("}", StyledString.DECORATIONS_STYLER).append(" - ", StyledString.QUALIFIER_STYLER).append(calledRule.getName(), StyledString.COUNTER_STYLER).append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
    } else {
        displayText = new StyledString("${", StyledString.DECORATIONS_STYLER).append(assignment.getFeature(), null).append("}", StyledString.DECORATIONS_STYLER).append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
    }
    ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
        configurable.setSelectionLength(proposalText.length() - 3);
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), '\t');
        configurable.setPriority(configurable.getPriority() * 2);
    }
    acceptor.accept(proposal);
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 7 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.

the class CodetemplatesProposalProvider method completeNestedKeyword.

public void completeNestedKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor, TemplateData data) {
    String keywordValue = keyword.getValue();
    String escapedKeywordValue = keywordValue.replace("$", "$$");
    StyledString displayString = new StyledString(keywordValue);
    if (!keywordValue.equals(escapedKeywordValue)) {
        displayString = new StyledString(escapedKeywordValue).append(" - ", StyledString.QUALIFIER_STYLER).append(keywordValue, StyledString.COUNTER_STYLER).append(" - Keyword", StyledString.QUALIFIER_STYLER);
    } else {
        displayString = displayString.append(" - Keyword", StyledString.QUALIFIER_STYLER);
    }
    ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) createCompletionProposal(escapedKeywordValue, displayString, getImage(keyword), contentAssistContext);
    getPriorityHelper().adjustKeywordPriority(proposal, contentAssistContext.getPrefix());
    if (proposal != null)
        proposal.setPriority(proposal.getPriority() * 2);
    acceptor.accept(proposal);
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 8 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.

the class TerminalsProposalProvider method createStringProposal.

private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor, String feature, RuleCall ruleCall) {
    String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
    proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
    String displayText = proposalText;
    if (feature != null)
        displayText = displayText + " - " + ruleCall.getRule().getName();
    ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset() + 1);
        configurable.setSelectionLength(proposalText.length() - 2);
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t');
    }
    acceptor.accept(proposal);
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 9 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-eclipse by eclipse.

the class TerminalsProposalProvider method complete_ID.

public void complete_ID(EObject model, RuleCall ruleCall, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (doCreateIdProposals()) {
        PrefixMatcher newMatcher = new PrefixMatcher() {

            @Override
            public boolean isCandidateMatchingPrefix(String name, String prefix) {
                String strippedName = name;
                if (name.startsWith("^") && !prefix.startsWith("^")) {
                    strippedName = name.substring(1);
                }
                return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
            }
        };
        ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
        String feature = getAssignedFeature(ruleCall);
        String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
        String displayText = proposalText;
        if (feature != null)
            displayText = proposalText + " - " + ruleCall.getRule().getName();
        proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
        ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
            configurable.setSelectionStart(configurable.getReplacementOffset());
            configurable.setSelectionLength(proposalText.length());
            configurable.setAutoInsertable(false);
            configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
        }
        acceptor.accept(proposal);
    }
}
Also used : PrefixMatcher(org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 10 with ConfigurableCompletionProposal

use of org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal in project xtext-xtend by eclipse.

the class EclipseBug28DirtyStateModifierContentAssistTest method getProposedText.

private static String getProposedText(ICompletionProposal completionProposal) {
    String proposedText = completionProposal.getDisplayString();
    if (completionProposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) completionProposal;
        proposedText = configurableProposal.getReplacementString();
        if (configurableProposal.getTextApplier() instanceof ReplacementTextApplier) {
            proposedText = ((ReplacementTextApplier) configurableProposal.getTextApplier()).getActualReplacementString(configurableProposal);
        }
    }
    return proposedText;
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ReplacementTextApplier(org.eclipse.xtext.ui.editor.contentassist.ReplacementTextApplier)

Aggregations

ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)35 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)21 StyledString (org.eclipse.jface.viewers.StyledString)16 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)8 PrefixMatcher (org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher)5 ContentAssistContext (org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)4 EObject (org.eclipse.emf.ecore.EObject)3 QualifiedName (org.eclipse.xtext.naming.QualifiedName)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 EClass (org.eclipse.emf.ecore.EClass)2 EClassifier (org.eclipse.emf.ecore.EClassifier)2 EPackage (org.eclipse.emf.ecore.EPackage)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 ContextTypeRegistry (org.eclipse.jface.text.templates.ContextTypeRegistry)2 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)2 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 EnumRule (org.eclipse.xtext.EnumRule)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 IScope (org.eclipse.xtext.scoping.IScope)2