Search in sources :

Example 1 with CompletionProposal

use of org.eclipse.che.ide.api.editor.codeassist.CompletionProposal in project che by eclipse.

the class JavaCodeAssistProcessor method showProposals.

private void showProposals(final CodeAssistCallback callback, final Proposals respons) {
    List<ProposalPresentation> presentations = respons.getProposals();
    final List<CompletionProposal> proposals = new ArrayList<>(presentations.size());
    HasLinkedMode linkedEditor = editor instanceof HasLinkedMode ? (HasLinkedMode) editor : null;
    for (final ProposalPresentation proposal : presentations) {
        final CompletionProposal completionProposal = new JavaCompletionProposal(proposal.getIndex(), insertStyle(resources, proposal.getDisplayString()), getIcon(proposal.getImage()), client, respons.getSessionId(), linkedEditor, refactoringUpdater, editorAgent);
        proposals.add(completionProposal);
    }
    callback.proposalComputed(proposals);
}
Also used : CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) HasLinkedMode(org.eclipse.che.ide.api.editor.link.HasLinkedMode) ProposalPresentation(org.eclipse.che.ide.ext.java.shared.dto.ProposalPresentation) ArrayList(java.util.ArrayList)

Example 2 with CompletionProposal

use of org.eclipse.che.ide.api.editor.codeassist.CompletionProposal in project che by eclipse.

the class JavaQuickAssistProcessor method showProposals.

private void showProposals(final CodeAssistCallback callback, final Proposals responds, TextEditor editor) {
    List<ProposalPresentation> presentations = responds.getProposals();
    final List<CompletionProposal> proposals = new ArrayList<>(presentations.size());
    HasLinkedMode linkedEditor = editor instanceof HasLinkedMode ? (HasLinkedMode) editor : null;
    for (ProposalPresentation proposal : presentations) {
        CompletionProposal completionProposal;
        String actionId = proposal.getActionId();
        if (actionId != null) {
            ProposalAction action = proposalActions.get(actionId);
            completionProposal = new ActionCompletionProposal(insertStyle(javaResources, proposal.getDisplayString()), actionId, action, JavaCodeAssistProcessor.getIcon(proposal.getImage()));
        } else {
            completionProposal = new JavaCompletionProposal(proposal.getIndex(), insertStyle(javaResources, proposal.getDisplayString()), JavaCodeAssistProcessor.getIcon(proposal.getImage()), client, responds.getSessionId(), linkedEditor, refactoringUpdater, editorAgent);
        }
        proposals.add(completionProposal);
    }
    callback.proposalComputed(proposals);
}
Also used : ProposalAction(org.eclipse.che.ide.ext.java.client.action.ProposalAction) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) HasLinkedMode(org.eclipse.che.ide.api.editor.link.HasLinkedMode) ProposalPresentation(org.eclipse.che.ide.ext.java.shared.dto.ProposalPresentation) ArrayList(java.util.ArrayList)

Example 3 with CompletionProposal

use of org.eclipse.che.ide.api.editor.codeassist.CompletionProposal in project che by eclipse.

the class QuickAssistWidget method createItem.

public Element createItem(final CompletionProposal proposal) {
    final Element element = Elements.createLiElement(popupResources.popupStyle().item());
    final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
    if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
    } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getImage().getElement());
    }
    element.appendChild(icon);
    final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
    label.setInnerHTML(proposal.getDisplayString());
    element.appendChild(label);
    final EventListener validateListener = new EventListener() {

        @Override
        public void handleEvent(final Event evt) {
            proposal.getCompletion(new CompletionProposal.CompletionCallback() {

                @Override
                public void onCompletion(final Completion completion) {
                    HandlesUndoRedo undoRedo = null;
                    if (textEditor instanceof UndoableEditor) {
                        UndoableEditor undoableEditor = (UndoableEditor) QuickAssistWidget.this.textEditor;
                        undoRedo = undoableEditor.getUndoRedo();
                    }
                    try {
                        if (undoRedo != null) {
                            undoRedo.beginCompoundChange();
                        }
                        completion.apply(textEditor.getDocument());
                        final LinearRange selection = completion.getSelection(textEditor.getDocument());
                        if (selection != null) {
                            textEditor.getDocument().setSelectedRange(selection, true);
                        }
                    } catch (final Exception e) {
                        Log.error(getClass(), e);
                    } finally {
                        if (undoRedo != null) {
                            undoRedo.endCompoundChange();
                        }
                    }
                }
            });
            hide();
        }
    };
    element.addEventListener(Event.DBLCLICK, validateListener, false);
    element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
    return element;
}
Also used : SpanElement(elemental.html.SpanElement) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) Completion(org.eclipse.che.ide.api.editor.codeassist.Completion) Event(elemental.events.Event) CustomEvent(elemental.events.CustomEvent) EventListener(elemental.events.EventListener)

Example 4 with CompletionProposal

use of org.eclipse.che.ide.api.editor.codeassist.CompletionProposal in project che by eclipse.

the class LanguageServerCodeAssistProcessor method computeProposals.

private void computeProposals(String currentWord, int offset, CodeAssistCallback callback) {
    List<CompletionProposal> proposals = newArrayList();
    for (CompletionItemDTO item : latestCompletionResult.getCompletionList().getItems()) {
        List<Match> highlights = filter(currentWord, item);
        if (highlights != null) {
            proposals.add(new CompletionItemBasedCompletionProposal(item, documentServiceClient, latestCompletionResult.getDocumentId(), resources, imageProvider.getIcon(item.getKind()), serverCapabilities, highlights, offset));
        }
    }
    callback.proposalComputed(proposals);
}
Also used : CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) CompletionItemDTO(org.eclipse.che.api.languageserver.shared.lsapi.CompletionItemDTO) Match(org.eclipse.che.plugin.languageserver.ide.filters.Match)

Example 5 with CompletionProposal

use of org.eclipse.che.ide.api.editor.codeassist.CompletionProposal in project che by eclipse.

the class ContentAssistWidget method createProposalPopupItem.

/**
     * Creates a new proposal item.
     *
     * @param index
     *         of proposal
     */
private Element createProposalPopupItem(int index) {
    final CompletionProposal proposal = proposals.get(index);
    final Element element = Elements.createLiElement(popupResources.popupStyle().item());
    element.setId(Integer.toString(index));
    final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
    if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
    } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getImage().getElement());
    }
    element.appendChild(icon);
    final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
    label.setInnerHTML(proposal.getDisplayString());
    element.appendChild(label);
    element.setTabIndex(1);
    final EventListener validateListener = evt -> applyProposal(proposal);
    element.addEventListener(Event.DBLCLICK, validateListener, false);
    element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
    element.addEventListener(Event.CLICK, event -> select(element), false);
    element.addEventListener(Event.FOCUS, this, false);
    element.addEventListener(DOCUMENTATION, new EventListener() {

        @Override
        public void handleEvent(Event event) {
            proposal.getAdditionalProposalInfo(new AsyncCallback<Widget>() {

                @Override
                public void onSuccess(Widget info) {
                    if (info != null) {
                        docPopup.clear();
                        docPopup.add(info);
                        docPopup.getElement().getStyle().setOpacity(1);
                        if (!docPopup.isAttached()) {
                            final int x = popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3;
                            final int y = popupElement.getOffsetTop();
                            RootPanel.get().add(docPopup);
                            updateMenuPosition(docPopup, x, y);
                        }
                    } else {
                        docPopup.getElement().getStyle().setOpacity(0);
                    }
                }

                @Override
                public void onFailure(Throwable e) {
                    Log.error(getClass(), e);
                    docPopup.getElement().getStyle().setOpacity(0);
                }
            });
        }
    }, false);
    return element;
}
Also used : SpanElement(elemental.html.SpanElement) OrionKeyModeOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionKeyModeOverlay) CustomEvent(elemental.events.CustomEvent) HTMLCollection(elemental.html.HTMLCollection) Elements(org.eclipse.che.ide.util.dom.Elements) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) OrionTextViewOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay) Assisted(com.google.inject.assistedinject.Assisted) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Style(com.google.gwt.dom.client.Style) Node(elemental.dom.Node) Element(elemental.dom.Element) AssistedInject(com.google.inject.assistedinject.AssistedInject) EventListener(elemental.events.EventListener) Window(elemental.html.Window) PopupResources(org.eclipse.che.ide.ui.popup.PopupResources) Event(elemental.events.Event) PX(elemental.css.CSSStyleDeclaration.Unit.PX) KeyboardEvent(elemental.events.KeyboardEvent) Completion(org.eclipse.che.ide.api.editor.codeassist.Completion) CompletionRequestEvent(org.eclipse.che.ide.api.editor.events.CompletionRequestEvent) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) RootPanel(com.google.gwt.user.client.ui.RootPanel) Log(org.eclipse.che.ide.util.loging.Log) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) Scheduler(com.google.gwt.core.client.Scheduler) Widget(com.google.gwt.user.client.ui.Widget) CompletionProposalExtension(org.eclipse.che.ide.api.editor.codeassist.CompletionProposalExtension) List(java.util.List) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) OrionPixelPositionOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionPixelPositionOverlay) KeyCodes(com.google.gwt.event.dom.client.KeyCodes) SpanElement(elemental.html.SpanElement) OrionModelChangedEventOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionModelChangedEventOverlay) Timer(com.google.gwt.user.client.Timer) EventTarget(elemental.events.EventTarget) MouseEvent(elemental.events.MouseEvent) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Widget(com.google.gwt.user.client.ui.Widget) CustomEvent(elemental.events.CustomEvent) Event(elemental.events.Event) KeyboardEvent(elemental.events.KeyboardEvent) CompletionRequestEvent(org.eclipse.che.ide.api.editor.events.CompletionRequestEvent) MouseEvent(elemental.events.MouseEvent) EventListener(elemental.events.EventListener)

Aggregations

CompletionProposal (org.eclipse.che.ide.api.editor.codeassist.CompletionProposal)5 Element (elemental.dom.Element)2 Node (elemental.dom.Node)2 CustomEvent (elemental.events.CustomEvent)2 Event (elemental.events.Event)2 EventListener (elemental.events.EventListener)2 SpanElement (elemental.html.SpanElement)2 ArrayList (java.util.ArrayList)2 Completion (org.eclipse.che.ide.api.editor.codeassist.Completion)2 HasLinkedMode (org.eclipse.che.ide.api.editor.link.HasLinkedMode)2 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)2 HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)2 UndoableEditor (org.eclipse.che.ide.api.editor.texteditor.UndoableEditor)2 ProposalPresentation (org.eclipse.che.ide.ext.java.shared.dto.ProposalPresentation)2 Scheduler (com.google.gwt.core.client.Scheduler)1 Style (com.google.gwt.dom.client.Style)1 KeyCodes (com.google.gwt.event.dom.client.KeyCodes)1 Timer (com.google.gwt.user.client.Timer)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1