use of org.graalvm.tools.lsp.server.types.DocumentHighlight in project graal by oracle.
the class HighlightRequestHandler method findOtherReadOrWrites.
List<? extends DocumentHighlight> findOtherReadOrWrites(TextDocumentSurrogate surrogate, InstrumentableNode nodeAtCaret, int line, int character) {
InteropUtils.VariableInfo[] caretVariables = InteropUtils.getNodeObjectVariables(nodeAtCaret);
if (caretVariables.length > 0) {
Set<String> variableNames = new HashSet<>();
for (InteropUtils.VariableInfo varInfo : caretVariables) {
if (contains(varInfo.getSourceSection(), line, character)) {
variableNames.add(varInfo.getName());
}
}
Object scope = getScope(surrogate, nodeAtCaret);
List<DocumentHighlight> highlights = new ArrayList<>();
while (scope != null) {
InteropLibrary interop = InteropLibrary.getUncached(scope);
if (interop.hasSourceLocation(scope)) {
try {
SourceSection sourceLocation = interop.getSourceLocation(scope);
Node[] nodeLocation = new Node[] { null };
EventBinding<LoadSourceSectionListener> binding = env.getInstrumenter().attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().sourceSectionEquals(sourceLocation).build(), e -> {
Node node = e.getNode();
if (nodeLocation[0] == null || isParent(node, nodeLocation[0])) {
nodeLocation[0] = node;
}
}, true);
binding.dispose();
addHighlights(nodeLocation[0], variableNames, highlights);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
if (interop.hasScopeParent(scope)) {
try {
scope = interop.getScopeParent(scope);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
} else {
scope = null;
}
}
return highlights;
}
return Collections.emptyList();
}
use of org.graalvm.tools.lsp.server.types.DocumentHighlight in project graal by oracle.
the class DocumentHighlightTest method checkHighlight.
private void checkHighlight(URI uri, int line, int column, DocumentHighlight... verifiedHighlights) throws InterruptedException, ExecutionException {
Future<List<? extends DocumentHighlight>> future = truffleAdapter.documentHighlight(uri, line, column);
List<? extends DocumentHighlight> highlights = future.get();
assertEquals(verifiedHighlights.length, highlights.size());
for (int i = 0; i < verifiedHighlights.length; i++) {
DocumentHighlight vh = verifiedHighlights[i];
DocumentHighlight h = highlights.get(i);
assertEquals(Integer.toString(i), vh.getKind(), h.getKind());
assertTrue(Integer.toString(i), rangeCheck(vh.getRange(), h.getRange()));
}
}
Aggregations