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