Search in sources :

Example 1 with ContentAssistEntry

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);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) TextRegion(org.eclipse.xtext.util.TextRegion) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) CompletionList(org.eclipse.lsp4j.CompletionList) List(java.util.List) IdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalAcceptor) IIdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor)

Example 2 with ContentAssistEntry

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));
    }
}
Also used : ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry)

Example 3 with ContentAssistEntry

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;
}
Also used : ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry)

Example 4 with ContentAssistEntry

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);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) TextRegion(org.eclipse.xtext.util.TextRegion) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) IdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalAcceptor) IIdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor)

Example 5 with ContentAssistEntry

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;
}
Also used : ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry)

Aggregations

ContentAssistEntry (org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry)7 IIdeContentProposalAcceptor (org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 Position (org.eclipse.lsp4j.Position)2 IdeContentProposalAcceptor (org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalAcceptor)2 TextRegion (org.eclipse.xtext.util.TextRegion)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ContentAssistContext (org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext)1 AbstractContentProposalProvider (org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider)1 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1