use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry in project xtext-core by eclipse.
the class ContentAssistService method createCompletionList.
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
try {
final CompletionList result = new CompletionList();
result.setIsIncomplete(true);
final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
final int caretOffset = document.getOffSet(params.getPosition());
final Position caretPosition = params.getPosition();
final TextRegion position = new TextRegion(caretOffset, 0);
try {
this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable) _t;
boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
boolean _not = (!_isOperationCanceledException);
if (_not) {
throw t;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
List<CompletionItem> _items = result.getItems();
_items.add(item);
};
IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry in project xtext-core by eclipse.
the class AbstractIdeTemplateProposalProvider method acceptProposal.
protected void acceptProposal(final String name, final String description, final StringConcatenationClient template, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor, final boolean adaptIndentation) {
final ContentAssistEntry entry = this.createProposal(template, context, adaptIndentation);
boolean _canAcceptProposal = this.canAcceptProposal(entry, context);
if (_canAcceptProposal) {
entry.setLabel(name);
entry.setDescription(description);
acceptor.accept(entry, this.proposalPriorities.getDefaultPriority(entry));
}
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry in project xtext-core by eclipse.
the class AbstractIdeTemplateProposalProvider method createProposal.
protected ContentAssistEntry createProposal(final StringConcatenationClient template, final ContentAssistContext context, final boolean adaptIndentation) {
final ContentAssistEntry entry = new ContentAssistEntry();
entry.setPrefix(context.getPrefix());
String _lineDelimiter = this.getLineDelimiter();
final AbstractIdeTemplateProposalProvider.TemplateStringConcatenation stringConcat = new AbstractIdeTemplateProposalProvider.TemplateStringConcatenation(context, entry, _lineDelimiter);
String _xifexpression = null;
if (adaptIndentation) {
_xifexpression = this.getIndentation(context);
} else {
_xifexpression = null;
}
final String indentation = _xifexpression;
if ((indentation == null)) {
stringConcat.append(template);
} else {
stringConcat.append(template, indentation);
}
entry.setProposal(stringConcat.toString());
return entry;
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry in project xtext-core by eclipse.
the class ContentAssistService method createCompletionList.
public CompletionList createCompletionList(Document document, XtextResource resource, CompletionParams params, CancelIndicator cancelIndicator) {
try {
CompletionList result = new CompletionList();
result.setIsIncomplete(true);
IdeContentProposalAcceptor acceptor = proposalAcceptorProvider.get();
int caretOffset = document.getOffSet(params.getPosition());
Position caretPosition = params.getPosition();
TextRegion position = new TextRegion(caretOffset, 0);
try {
createProposals(document.getContents(), position, caretOffset, resource, acceptor);
} catch (Throwable t) {
if (!operationCanceledManager.isOperationCanceledException(t)) {
throw t;
}
}
int idx = 0;
for (ContentAssistEntry it : acceptor.getEntries()) {
CompletionItem item = toCompletionItem(it, caretOffset, caretPosition, document);
item.setSortText(Strings.padStart(Integer.toString(idx), 5, '0'));
result.getItems().add(item);
idx++;
}
return result;
} catch (Throwable e) {
throw Exceptions.sneakyThrow(e);
}
}
use of org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry in project xtext-core by eclipse.
the class IdeContentProposalCreator method createProposal.
/**
* Returns an entry with the given proposal and prefix, or null if the proposal is not valid.
* If it is valid, the initializer function is applied to it.
*/
public ContentAssistEntry createProposal(final String proposal, final String prefix, final ContentAssistContext context, final String kind, final Procedure1<? super ContentAssistEntry> init) {
boolean _isValidProposal = this.isValidProposal(proposal, prefix, context);
if (_isValidProposal) {
final ContentAssistEntry result = new ContentAssistEntry();
result.setProposal(proposal);
result.setPrefix(prefix);
if ((kind != null)) {
result.setKind(kind);
}
if ((init != null)) {
init.apply(result);
}
return result;
}
return null;
}
Aggregations