Search in sources :

Example 6 with CoverageData

use of org.graalvm.tools.lsp.server.utils.CoverageData in project graal by oracle.

the class CompletionRequestHandler method fillCompletionsWithGlobalsAndLocals.

private void fillCompletionsWithGlobalsAndLocals(int line, TextDocumentSurrogate surrogate, int column, List<CompletionItem> completions) {
    Node nearestNode = findNearestNode(surrogate.getSourceWrapper(), line, column);
    if (nearestNode == null) {
        // Cannot locate a valid node near the caret position, therefore provide globals only
        fillCompletionsWithGlobals(surrogate, completions);
        return;
    }
    if (!surrogate.hasCoverageData()) {
        // No coverage data, so we simply display locals without specific frame information and
        // globals
        fillCompletionsWithLocals(surrogate, nearestNode, completions, null);
        fillCompletionsWithGlobals(surrogate, completions);
        return;
    }
    // We have coverage data, so we try to derive locals from coverage data
    List<CoverageData> coverages = surrogate.getCoverageData(nearestNode.getSourceSection());
    if (coverages == null || coverages.isEmpty()) {
        coverages = SourceCodeEvaluator.findCoverageDataBeforeNode(surrogate, nearestNode);
    }
    if (coverages != null && !coverages.isEmpty()) {
        CoverageData coverageData = coverages.get(coverages.size() - 1);
        MaterializedFrame frame = coverageData.getFrame();
        fillCompletionsWithLocals(surrogate, nearestNode, completions, frame);
        // Call again, regardless if it was called with a frame argument before,
        // because duplicates will be filter, but it will add missing local
        // variables which were dropped (because of null values) in the call above
        fillCompletionsWithLocals(surrogate, nearestNode, completions, null);
        fillCompletionsWithGlobals(surrogate, completions);
    } else {
        // No coverage data found for the designated source section, so use the default look-up
        // as fallback
        fillCompletionsWithGlobals(surrogate, completions);
        fillCompletionsWithLocals(surrogate, nearestNode, completions, null);
    }
}
Also used : CoverageData(org.graalvm.tools.lsp.server.utils.CoverageData) Node(com.oracle.truffle.api.nodes.Node) NearestNode(org.graalvm.tools.lsp.server.utils.NearestNode) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Aggregations

CoverageData (org.graalvm.tools.lsp.server.utils.CoverageData)6 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)3 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)3 Node (com.oracle.truffle.api.nodes.Node)3 CoverageEventNode (org.graalvm.tools.lsp.server.utils.CoverageEventNode)3 MaterializedFrame (com.oracle.truffle.api.frame.MaterializedFrame)2 NodeLibrary (com.oracle.truffle.api.interop.NodeLibrary)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)1 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)1 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)1 Source (com.oracle.truffle.api.source.Source)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EvaluationResultException (org.graalvm.tools.lsp.exceptions.EvaluationResultException)1