use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext in project xtext-eclipse by eclipse.
the class UiToIdeContentProposalProvider method getIdeContext.
private ContentAssistContext getIdeContext(final org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext c) {
final ContentAssistContext.Builder builder = this.builderProvider.get();
final Region replaceRegion = c.getReplaceRegion();
ContentAssistContext.Builder _setOffset = builder.setPrefix(c.getPrefix()).setSelectedText(c.getSelectedText()).setRootModel(c.getRootModel()).setRootNode(c.getRootNode()).setCurrentModel(c.getCurrentModel()).setPreviousModel(c.getPreviousModel()).setCurrentNode(c.getCurrentNode()).setLastCompleteNode(c.getLastCompleteNode()).setOffset(c.getOffset());
int _offset = replaceRegion.getOffset();
int _length = replaceRegion.getLength();
TextRegion _textRegion = new TextRegion(_offset, _length);
_setOffset.setReplaceRegion(_textRegion).setResource(c.getResource());
ImmutableList<AbstractElement> _firstSetGrammarElements = c.getFirstSetGrammarElements();
for (final AbstractElement grammarElement : _firstSetGrammarElements) {
builder.accept(grammarElement);
}
return builder.toContext();
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext in project xtext-eclipse by eclipse.
the class UiToIdeContentProposalProvider method createProposals.
@Override
public void createProposals(final org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
final ArrayList<Pair<ContentAssistEntry, Integer>> entries = new ArrayList<Pair<ContentAssistEntry, Integer>>();
final IIdeContentProposalAcceptor ideAcceptor = new IIdeContentProposalAcceptor() {
@Override
public void accept(final ContentAssistEntry entry, final int priority) {
if ((entry != null)) {
Pair<ContentAssistEntry, Integer> _mappedTo = Pair.<ContentAssistEntry, Integer>of(entry, Integer.valueOf(priority));
entries.add(_mappedTo);
}
}
@Override
public boolean canAcceptMoreProposals() {
int _size = entries.size();
int _maxProposals = UiToIdeContentProposalProvider.this.getMaxProposals();
return (_size < _maxProposals);
}
};
ContentAssistContext _ideContext = this.getIdeContext(context);
this.ideProvider.createProposals(Collections.<ContentAssistContext>unmodifiableList(CollectionLiterals.<ContentAssistContext>newArrayList(_ideContext)), ideAcceptor);
final AbstractContentProposalProvider.NullSafeCompletionProposalAcceptor uiAcceptor = new AbstractContentProposalProvider.NullSafeCompletionProposalAcceptor(acceptor);
final Procedure2<Pair<ContentAssistEntry, Integer>, Integer> _function = (Pair<ContentAssistEntry, Integer> p, Integer idx) -> {
final ContentAssistEntry entry = p.getKey();
final ConfigurableCompletionProposal proposal = this.doCreateProposal(entry.getProposal(), this.getDisplayString(entry), this.getImage(entry), (p.getValue()).intValue(), context);
uiAcceptor.accept(proposal);
};
IterableExtensions.<Pair<ContentAssistEntry, Integer>>forEach(entries, _function);
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext in project xtext-core by eclipse.
the class ContentAssistContextTestHelper method firstSetGrammarElementsToString.
public String firstSetGrammarElementsToString(ContentAssistContextFactory factory) throws Exception {
int offset = document.indexOf(cursor);
Preconditions.checkArgument(offset >= 0, "you forgot to provide a cursor");
String doc = document.replace(cursor, "");
XtextResource res = parse(doc);
factory.setPool(Executors.newCachedThreadPool());
ContentAssistContext[] ctxs = factory.create(doc, new TextRegion(0, 0), offset, res);
GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
Iterable<String> entries = Iterables.transform(IterableExtensions.indexed(Arrays.asList(ctxs)), ctx -> {
String elements = Joiner.on("").join(Lists.transform(ctx.getValue().getFirstSetGrammarElements(), ele -> " " + ele.eClass().getName() + ": " + f.apply(ele) + "\n"));
String entry = "context" + ctx.getKey() + " {\n" + elements + "}\n";
return entry;
});
String result = Joiner.on("").join(entries);
return result;
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext in project xtext-core by eclipse.
the class ContentAssistService method createProposals.
protected void createProposals(String document, TextRegion selection, int caretOffset, XtextResource resource, IIdeContentProposalAcceptor acceptor) {
if (caretOffset > document.length()) {
return;
}
ContentAssistContextFactory contextFactory = contextFactoryProvider.get();
contextFactory.setPool(executorService);
ContentAssistContext[] contexts = contextFactory.create(document, selection, caretOffset, resource);
proposalProvider.createProposals(Arrays.asList(contexts), acceptor);
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext in project xtext-core by eclipse.
the class ContentAssistContextFactory method isLikelyToBeValidProposal.
protected boolean isLikelyToBeValidProposal(INode lastCompleteNode, Iterable<ContentAssistContext> contexts) {
for (ContentAssistContext context : contexts) {
for (AbstractElement element : context.getFirstSetGrammarElements()) {
if (element instanceof Keyword) {
String keywordValue = ((Keyword) element).getValue();
String lastText = ((ILeafNode) lastCompleteNode).getText();
if (keywordValue.equals(lastText))
return true;
}
}
}
return false;
}
Aggregations