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

Render hover messages according to LSP specification #2856

Merged
merged 1 commit into from
Oct 26, 2016
Merged
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 @@ -10,13 +10,12 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.ide.hover;

import com.google.common.base.Joiner;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.languageserver.shared.lsapi.HoverDTO;
import org.eclipse.che.api.languageserver.shared.lsapi.MarkedStringDTO;
import org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO;
import org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO;
import org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO;
import org.eclipse.che.api.promises.client.Function;
import org.eclipse.che.api.promises.client.FunctionException;
Expand All @@ -34,6 +33,11 @@
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient;
import org.eclipse.che.plugin.languageserver.ide.util.DtoBuildHelper;

import java.util.ArrayList;
import java.util.List;

import io.typefox.lsapi.MarkedString;

/**
* Provides hover LS functionality for Orion editor.
*
Expand Down Expand Up @@ -80,11 +84,7 @@ public JsPromise<OrionHoverOverlay> computeHover(OrionHoverContextOverlay contex
public OrionHoverOverlay apply(HoverDTO arg) throws FunctionException {
OrionHoverOverlay hover = OrionHoverOverlay.create();
hover.setType("markdown");
StringBuilder b = new StringBuilder();
for (MarkedStringDTO dto : arg.getContents()) {
b.append(dto.getValue());
}
String content = b.toString();
String content = renderContent(arg);
//do not show hover with only white spaces
if (StringUtils.isNullOrWhitespace(content)) {
return null;
Expand All @@ -93,6 +93,21 @@ public OrionHoverOverlay apply(HoverDTO arg) throws FunctionException {

return hover;
}

private String renderContent(HoverDTO hover) {
List<String> contents = new ArrayList<String>();
for (MarkedStringDTO dto : hover.getContents()) {
String lang = dto.getLanguage();
if (lang == null || MarkedString.PLAIN_STRING.equals(lang)) {
// plain markdown text
contents.add(dto.getValue());
} else {
// markdown code block
contents.add("```" + lang + "\n" + dto.getValue() + "\n```");
}
}
return Joiner.on("\n\n").join(contents);
}
});
return (JsPromise<OrionHoverOverlay>)then;

Expand Down