use of org.graalvm.tools.lsp.server.types.MarkupContent in project graal by oracle.
the class HoverRequestHandler method createDefaultHoverInfos.
@SuppressWarnings("deprecation")
private List<Object> createDefaultHoverInfos(String textAtHoverPosition, Object evalResultObject, LanguageInfo langInfo) {
List<Object> contents = new ArrayList<>();
contents.add(org.graalvm.tools.lsp.server.types.MarkedString.create(langInfo.getId(), textAtHoverPosition));
String result = evalResultObject != null ? toString(evalResultObject, langInfo) : "";
if (!textAtHoverPosition.equals(result)) {
String resultObjectString = evalResultObject instanceof String ? "\"" + result + "\"" : result;
contents.add(resultObjectString);
}
String detailText = completionHandler.createCompletionDetail(evalResultObject, langInfo);
contents.add("meta-object: " + detailText);
Object documentation = completionHandler.getDocumentation(evalResultObject, langInfo);
if (documentation instanceof String) {
contents.add(documentation);
} else if (documentation instanceof MarkupContent) {
MarkupContent markup = (MarkupContent) documentation;
if (markup.getKind().equals(MarkupKind.PlainText)) {
contents.add(markup.getValue());
} else {
contents.add(org.graalvm.tools.lsp.server.types.MarkedString.create(langInfo.getId(), markup.getValue()));
}
}
return contents;
}
use of org.graalvm.tools.lsp.server.types.MarkupContent in project graal by oracle.
the class HoverRequestHandler method trySignature.
@SuppressWarnings("deprecation")
private Hover trySignature(SourceSection hoverSection, LanguageInfo langInfo, TruffleObject evalResult) {
String formattedSignature = completionHandler.getFormattedSignature(evalResult, langInfo);
if (formattedSignature != null) {
List<Object> contents = new ArrayList<>();
contents.add(org.graalvm.tools.lsp.server.types.MarkedString.create(langInfo.getId(), formattedSignature));
Object documentation = completionHandler.getDocumentation(evalResult, langInfo);
if (documentation instanceof String) {
contents.add(documentation);
} else if (documentation instanceof MarkupContent) {
MarkupContent markup = (MarkupContent) documentation;
if (markup.getKind().equals(MarkupKind.PlainText)) {
contents.add(markup.getValue());
} else {
contents.add(org.graalvm.tools.lsp.server.types.MarkedString.create(langInfo.getId(), markup.getValue()));
}
}
return Hover.create(contents).setRange(SourceUtils.sourceSectionToRange(hoverSection));
}
return null;
}
use of org.graalvm.tools.lsp.server.types.MarkupContent in project graal by oracle.
the class HoverRequestHandler method hoverWithEnteredContext.
public Hover hoverWithEnteredContext(URI uri, int line, int column) {
TextDocumentSurrogate surrogate = surrogateMap.get(uri);
InstrumentableNode nodeAtCaret = findNodeAtCaret(surrogate, line, column);
if (nodeAtCaret != null) {
SourceSection hoverSection = ((Node) nodeAtCaret).getSourceSection();
logger.log(Level.FINER, "Hover: SourceSection({0})", hoverSection.getCharacters());
if (surrogate.hasCoverageData()) {
List<CoverageData> coverages = surrogate.getCoverageData(hoverSection);
if (coverages != null) {
return evalHoverInfos(coverages, hoverSection, surrogate.getLanguageInfo());
}
} else if (developerMode) {
String sourceText = hoverSection.getCharacters().toString();
MarkupContent content = MarkupContent.create(MarkupKind.PlainText, "Language: " + surrogate.getLanguageId() + ", Section: " + sourceText + "\n" + "Node class: " + nodeAtCaret.getClass().getSimpleName() + "\n" + "Tags: " + getTags(nodeAtCaret));
return Hover.create(content).setRange(SourceUtils.sourceSectionToRange(hoverSection));
}
}
return Hover.create(Collections.emptyList());
}
Aggregations