Search in sources :

Example 1 with Hover

use of org.graalvm.tools.lsp.server.types.Hover in project graal by oracle.

the class HoverTest method checkHover.

private Hover checkHover(URI uri, int line, int column, Range range) throws InterruptedException, ExecutionException {
    Future<Hover> future = truffleAdapter.hover(uri, line, column);
    Hover hover = future.get();
    assertTrue(rangeCheck(range, hover.getRange()));
    return hover;
}
Also used : Hover(org.graalvm.tools.lsp.server.types.Hover)

Example 2 with Hover

use of org.graalvm.tools.lsp.server.types.Hover in project graal by oracle.

the class HoverRequestHandler method tryCoverageDataEvaluation.

private Hover tryCoverageDataEvaluation(SourceSection hoverSection, LanguageInfo langInfo, String textAtHoverPosition, CoverageData coverageData) {
    InstrumentableNode instrumentable = ((InstrumentableNode) coverageData.getCoverageEventNode().getInstrumentedNode());
    if (!instrumentable.hasTag(StandardTags.ExpressionTag.class)) {
        return null;
    }
    Future<Hover> future = contextAwareExecutor.executeWithNestedContext(() -> {
        final LanguageInfo rootLangInfo = coverageData.getCoverageEventNode().getRootNode().getLanguageInfo();
        final Source inlineEvalSource = Source.newBuilder(rootLangInfo.getId(), textAtHoverPosition, "in-line eval (hover request)").cached(false).build();
        ExecutableNode executableNode = null;
        try {
            executableNode = env.parseInline(inlineEvalSource, coverageData.getCoverageEventNode(), coverageData.getFrame());
        } catch (Exception e) {
        }
        if (executableNode == null) {
            return Hover.create(Collections.emptyList());
        }
        CoverageEventNode coverageEventNode = coverageData.getCoverageEventNode();
        coverageEventNode.insertOrReplaceChild(executableNode);
        Object evalResult = null;
        try {
            logger.fine("Trying coverage-based eval...");
            evalResult = executableNode.execute(coverageData.getFrame());
        } catch (Exception e) {
            if (!(INTEROP.isException(e) || (e instanceof ControlFlowException))) {
                e.printStackTrace(err);
            }
            return Hover.create(Collections.emptyList());
        } finally {
            coverageEventNode.clearChild();
        }
        if (evalResult instanceof TruffleObject) {
            Hover signatureHover = trySignature(hoverSection, langInfo, (TruffleObject) evalResult);
            if (signatureHover != null) {
                return signatureHover;
            }
        }
        return Hover.create(createDefaultHoverInfos(textAtHoverPosition, evalResult, langInfo)).setRange(SourceUtils.sourceSectionToRange(hoverSection));
    }, true);
    return getFutureResultOrHandleExceptions(future);
}
Also used : InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) ControlFlowException(com.oracle.truffle.api.nodes.ControlFlowException) Hover(org.graalvm.tools.lsp.server.types.Hover) CoverageEventNode(org.graalvm.tools.lsp.server.utils.CoverageEventNode) ExpressionTag(com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) Source(com.oracle.truffle.api.source.Source) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) ControlFlowException(com.oracle.truffle.api.nodes.ControlFlowException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 3 with Hover

use of org.graalvm.tools.lsp.server.types.Hover in project graal by oracle.

the class HoverRequestHandler method evalHoverInfos.

private Hover evalHoverInfos(List<CoverageData> coverages, SourceSection hoverSection, LanguageInfo langInfo) {
    String textAtHoverPosition = hoverSection.getCharacters().toString();
    for (CoverageData coverageData : coverages) {
        Hover frameSlotHover = tryFrameScope(coverageData.getFrame(), coverageData.getCoverageEventNode(), textAtHoverPosition, langInfo, hoverSection);
        if (frameSlotHover != null) {
            return frameSlotHover;
        }
        Hover coverageDataHover = tryCoverageDataEvaluation(hoverSection, langInfo, textAtHoverPosition, coverageData);
        if (coverageDataHover != null) {
            return coverageDataHover;
        }
    }
    return Hover.create(Collections.emptyList());
}
Also used : CoverageData(org.graalvm.tools.lsp.server.utils.CoverageData) Hover(org.graalvm.tools.lsp.server.types.Hover)

Example 4 with Hover

use of org.graalvm.tools.lsp.server.types.Hover in project graal by oracle.

the class HoverTest method hoverWithCoverageDataAvailable.

@Test
public void hoverWithCoverageDataAvailable() throws InterruptedException, ExecutionException {
    URI uri = createDummyFileUriForSL();
    Future<?> futureOpen = truffleAdapter.parse(PROG_OBJ, "sl", uri);
    futureOpen.get();
    Future<Boolean> futureCoverage = truffleAdapter.runCoverageAnalysis(uri);
    assertTrue(futureCoverage.get());
    Hover hover = checkHover(uri, 8, 10, Range.create(Position.create(8, 9), Position.create(8, 12)));
    assertTrue(hover.getContents() instanceof List);
    assertEquals(3, ((List<?>) hover.getContents()).size());
    assertTrue(((List<?>) hover.getContents()).get(0) instanceof org.graalvm.tools.lsp.server.types.MarkedString);
    assertEquals("obj", ((org.graalvm.tools.lsp.server.types.MarkedString) ((List<?>) hover.getContents()).get(0)).getValue());
    assertEquals("Object", ((List<?>) hover.getContents()).get(1));
    assertEquals("meta-object: Object", ((List<?>) hover.getContents()).get(2));
}
Also used : Hover(org.graalvm.tools.lsp.server.types.Hover) List(java.util.List) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Hover (org.graalvm.tools.lsp.server.types.Hover)4 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)1 ExpressionTag (com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag)1 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 ControlFlowException (com.oracle.truffle.api.nodes.ControlFlowException)1 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 Source (com.oracle.truffle.api.source.Source)1 URI (java.net.URI)1 List (java.util.List)1 CoverageData (org.graalvm.tools.lsp.server.utils.CoverageData)1 CoverageEventNode (org.graalvm.tools.lsp.server.utils.CoverageEventNode)1 Test (org.junit.Test)1