Search in sources :

Example 1 with MarkupContent

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

Example 2 with MarkupContent

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

Example 3 with MarkupContent

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());
}
Also used : InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) CoverageData(org.graalvm.tools.lsp.server.utils.CoverageData) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) CoverageEventNode(org.graalvm.tools.lsp.server.utils.CoverageEventNode) TextDocumentSurrogate(org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate) SourceSection(com.oracle.truffle.api.source.SourceSection) MarkupContent(org.graalvm.tools.lsp.server.types.MarkupContent)

Aggregations

MarkupContent (org.graalvm.tools.lsp.server.types.MarkupContent)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 ArrayList (java.util.ArrayList)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)1 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)1 Node (com.oracle.truffle.api.nodes.Node)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 CoverageData (org.graalvm.tools.lsp.server.utils.CoverageData)1 CoverageEventNode (org.graalvm.tools.lsp.server.utils.CoverageEventNode)1 TextDocumentSurrogate (org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate)1