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);
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations