Search in sources :

Example 1 with MarkupKind

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;
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) MarkupKind(org.graalvm.tools.lsp.server.types.MarkupKind) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

InteropException (com.oracle.truffle.api.interop.InteropException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 MarkupKind (org.graalvm.tools.lsp.server.types.MarkupKind)1