use of org.graalvm.tools.lsp.server.types.MarkupKind in project graal by oracle.
the class CompletionRequestHandler method getDocumentation.
public Object getDocumentation(Object value, LanguageInfo langInfo) {
if (!(value instanceof TruffleObject) || INTEROP.isNull(value)) {
return null;
}
try {
Object docu = LSP_INTEROP.getDocumentation(value);
if (docu instanceof String && !((String) docu).isEmpty()) {
return docu;
} else {
if (docu instanceof TruffleObject) {
TruffleObject markup = (TruffleObject) docu;
MarkupKind markupKind = null;
String text = null;
if (INTEROP.isMemberReadable(markup, "kind")) {
Object kind = INTEROP.readMember(markup, "kind");
if (kind instanceof String) {
markupKind = MarkupKind.get((String) kind);
}
}
if (markupKind == null) {
markupKind = MarkupKind.PlainText;
}
if (INTEROP.isMemberReadable(markup, "value")) {
Object v = INTEROP.readMember(markup, "value");
if (v instanceof String) {
text = (String) v;
}
}
assert text != null : "No documentation value is provided from " + docu;
if (text != null) {
return MarkupContent.create(markupKind, text);
} else {
return MarkupContent.create(markupKind, languageToString(langInfo, docu));
}
}
}
} catch (UnsupportedMessageException e) {
// GET_DOCUMENTATION message is not supported
} catch (InteropException e) {
e.printStackTrace(err);
}
return null;
}
Aggregations