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;
}
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);
}
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());
}
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));
}
Aggregations