Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-3218: improves the documentation popup for LSP code completion #3224

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import io.typefox.lsapi.ServerCapabilities;

import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

import org.eclipse.che.api.languageserver.shared.lsapi.CompletionItemDTO;
Expand All @@ -37,6 +38,8 @@

import java.util.List;

import static org.eclipse.che.ide.api.theme.Style.theme;

/**
* @author Anatolii Bazko
* @author Kaloyan Raev
Expand Down Expand Up @@ -99,12 +102,15 @@ private Widget createAdditionalInfoWidget() {
documentation = "No documentation found.";
}

Label label = new Label(documentation);
label.setWordWrap(true);
label.getElement().getStyle().setFontSize(13, Style.Unit.PX);
label.getElement().getStyle().setMarginLeft(4, Style.Unit.PX);
label.setSize("100%", "100%");
return label;
HTML widget = new HTML(documentation);
widget.setWordWrap(true);
widget.getElement().getStyle().setColor(theme.completionPopupItemTextColor());
widget.getElement().getStyle().setFontSize(13, Style.Unit.PX);
widget.getElement().getStyle().setMarginLeft(4, Style.Unit.PX);
widget.getElement().getStyle().setOverflow(Overflow.AUTO);
widget.getElement().getStyle().setProperty("userSelect", "text");
widget.setHeight("100%");
return widget;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public void handleEvent(final Event evt) {
final EventTarget target = mouseEvent.getTarget();
if (target instanceof Element) {
final Element elementTarget = (Element)target;
if (elementTarget.equals(docPopup.getElement()) && docPopup.isVisible()) {
if (docPopup.isVisible() &&
(elementTarget.equals(docPopup.getElement()) ||
elementTarget.getParentElement().equals(docPopup.getElement()))) {
return;
}

Expand Down Expand Up @@ -219,16 +221,11 @@ public void onSuccess(Widget info) {
if (info != null) {
docPopup.clear();
docPopup.add(info);
docPopup.getElement().getStyle().setOpacity(1);

if (docPopup.isAttached()) {
return;
if (!docPopup.isAttached()) {
RootPanel.get().add(docPopup);
}

docPopup.getElement().getStyle()
.setLeft(popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3, Style.Unit.PX);
docPopup.getElement().getStyle().setTop(popupElement.getOffsetTop(), Style.Unit.PX);
RootPanel.get().add(docPopup);
docPopup.getElement().getStyle().setOpacity(1);
} else {
docPopup.getElement().getStyle().setOpacity(0);
}
Expand Down Expand Up @@ -412,7 +409,6 @@ private void select(Element element) {
selectedElement = element;
selectedElement.setAttribute("selected", "true");

docPopup.clear();
showDocTimer.cancel();
showDocTimer.schedule(docPopup.isAttached() ? 100 : 1500);

Expand Down Expand Up @@ -521,7 +517,7 @@ public void show(final List<CompletionProposal> proposals) {
this.popupElement.getStyle().setProperty("maxWidth", viewportWidth + caretLocation.getX() + "px");
}

/* Don't attach handlers twice. Visible popup must already their attached. */
/* Don't attach handlers twice. Visible popup must already have their attached. */
if (!visible) {
addPopupEventListeners();
}
Expand All @@ -530,16 +526,11 @@ public void show(final List<CompletionProposal> proposals) {
visible = true;
focused = false;

if (docPopup.isAttached()) {
docPopup.getElement().getStyle().setOpacity(0);
new Timer() {
@Override
public void run() {
docPopup.removeFromParent();
showDocTimer.schedule(1500);
}
}.schedule(250);
}
/* Update documentation popup position */
docPopup.getElement().getStyle()
.setLeft(popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3, Style.Unit.PX);
docPopup.getElement().getStyle()
.setTop(popupElement.getOffsetTop(), Style.Unit.PX);

/* Select first row. */
selectFirst();
Expand Down