use of org.graalvm.tools.lsp.exceptions.DiagnosticsNotification in project graal by oracle.
the class CompletionTest method objectPropertyCompletionLocalFile.
@Test
public void objectPropertyCompletionLocalFile() throws InterruptedException, ExecutionException {
URI uri = createDummyFileUriForSL();
Future<?> future = truffleAdapter.parse(PROG_OBJ_NOT_CALLED, "sl", uri);
future.get();
setTriggerCharacters();
replace(uri, Range.create(Position.create(2, 12), Position.create(2, 12)), ".", "extraneous input '.'");
Future<CompletionList> futureC = truffleAdapter.completion(uri, 2, 13, null);
CompletionList completionList = futureC.get();
assertEquals(1, completionList.getItems().size());
CompletionItem item = completionList.getItems().get(0);
assertEquals("p", item.getLabel());
assertEquals("Number", item.getDetail());
assertEquals(CompletionItemKind.Property, item.getKind());
replace(uri, Range.create(Position.create(2, 12), Position.create(2, 13)), "", null);
replace(uri, Range.create(Position.create(12, 7), Position.create(12, 7)), ".", "missing IDENTIFIER");
futureC = truffleAdapter.completion(uri, 12, 8, null);
try {
futureC.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof DiagnosticsNotification);
}
}
use of org.graalvm.tools.lsp.exceptions.DiagnosticsNotification in project graal by oracle.
the class ParsingTest method parseingWithSyntaxErrors.
@Test
public void parseingWithSyntaxErrors() throws InterruptedException {
URI uri = createDummyFileUriForSL();
String text = "function main() {return 3+;}";
Future<?> future = truffleAdapter.parse(text, "sl", uri);
try {
future.get();
fail();
} catch (ExecutionException e) {
DiagnosticsNotification diagnosticsNotification = getDiagnosticsNotification(e);
Collection<PublishDiagnosticsParams> diagnosticParamsCollection = diagnosticsNotification.getDiagnosticParamsCollection();
assertEquals(1, diagnosticParamsCollection.size());
PublishDiagnosticsParams diagnosticsParams = diagnosticParamsCollection.iterator().next();
assertEquals(1, diagnosticsParams.getDiagnostics().size());
assertTrue(rangeCheck(0, 26, 0, 27, diagnosticsParams.getDiagnostics().get(0).getRange()));
}
}
use of org.graalvm.tools.lsp.exceptions.DiagnosticsNotification in project graal by oracle.
the class CoverageRequestHandler method runCoverageAnalysisWithEnteredContext.
public Boolean runCoverageAnalysisWithEnteredContext(final URI uri) throws DiagnosticsNotification {
final TextDocumentSurrogate surrogateOfOpenedFile = surrogateMap.get(uri);
if (surrogateOfOpenedFile == null) {
return Boolean.FALSE;
}
TextDocumentSurrogate surrogateOfTestFile = sourceCodeEvaluator.createSurrogateForTestFile(surrogateOfOpenedFile, null);
final URI runScriptUri = surrogateOfTestFile.getUri();
clearRelatedCoverageData(runScriptUri);
try {
final CallTarget callTarget = sourceCodeEvaluator.parse(surrogateOfTestFile);
LanguageInfo languageInfo = surrogateOfTestFile.getLanguageInfo();
SourcePredicate predicate = SourcePredicateBuilder.newBuilder().language(languageInfo).excludeInternal(env.getOptions()).build();
SourceSectionFilter eventFilter = SourceSectionFilter.newBuilder().sourceIs(predicate).build();
EventBinding<ExecutionEventNodeFactory> eventFactoryBinding = env.getInstrumenter().attachExecutionEventFactory(eventFilter, new ExecutionEventNodeFactory() {
private final long creatorThreadId = Thread.currentThread().getId();
@Override
public ExecutionEventNode create(final EventContext eventContext) {
final SourceSection section = eventContext.getInstrumentedSourceSection();
if (section != null && section.isAvailable()) {
final Node instrumentedNode = eventContext.getInstrumentedNode();
Function<URI, TextDocumentSurrogate> func = (sourceUri) -> {
return surrogateMap.getOrCreateSurrogate(sourceUri, () -> instrumentedNode.getRootNode().getLanguageInfo());
};
return new CoverageEventNode(section, instrumentedNode, runScriptUri, func, creatorThreadId);
} else {
return null;
}
}
});
try {
callTarget.call();
} finally {
eventFactoryBinding.dispose();
}
surrogateOfOpenedFile.setCoverageAnalysisDone(true);
return Boolean.TRUE;
} catch (DiagnosticsNotification e) {
throw e;
} catch (Exception e) {
InteropLibrary interopLib = InteropLibrary.getUncached();
if (interopLib.isException(e)) {
SourceSection sourceSection;
try {
sourceSection = interopLib.hasSourceLocation(e) ? interopLib.getSourceLocation(e) : null;
} catch (UnsupportedMessageException um) {
throw CompilerDirectives.shouldNotReachHere(um);
}
URI uriOfErronousSource = sourceSection != null ? sourceSection.getSource().getURI() : null;
if (uriOfErronousSource == null) {
uriOfErronousSource = uri;
}
throw DiagnosticsNotification.create(uriOfErronousSource, Diagnostic.create(SourceUtils.getRangeFrom(e, interopLib), e.getMessage(), DiagnosticSeverity.Error, null, "Coverage analysis", null));
}
throw e;
}
}
Aggregations