use of org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate in project graal by oracle.
the class ParsingTest method changeAndParse.
@Test
public void changeAndParse() throws InterruptedException, ExecutionException {
TextDocumentSurrogate surrogate;
URI uri = createDummyFileUriForSL();
String text = "function main() {return 3+3;}";
Future<?> futureParse = truffleAdapter.parse(text, "sl", uri);
futureParse.get();
// Insert +4
checkChange(uri, Range.create(Position.create(0, 27), Position.create(0, 27)), "+4", "function main() {return 3+3+4;}");
// Delete
checkChange(uri, Range.create(Position.create(0, 24), Position.create(0, 26)), "", "function main() {return 3+4;}");
// Replace
checkChange(uri, Range.create(Position.create(0, 17), Position.create(0, 29)), "\n return 42;\n}", "function main() {\n return 42;\n}");
// Insert at the end
checkChange(uri, Range.create(Position.create(2, 1), Position.create(2, 1)), "\n", "function main() {\n return 42;\n}\n");
checkChange(uri, Range.create(Position.create(3, 0), Position.create(3, 0)), " ", "function main() {\n return 42;\n}\n ");
// Multiline replace
checkChange(uri, Range.create(Position.create(0, 16), Position.create(3, 1)), "{return 1;}", "function main() {return 1;}");
// No change
surrogate = checkChange(uri, Range.create(Position.create(0, 1), Position.create(0, 1)), "", "function main() {return 1;}");
// Replace to empty
try {
checkChange(uri, Range.create(Position.create(0, 0), Position.create(0, 30)), "", null);
fail();
} catch (ExecutionException e) {
Collection<PublishDiagnosticsParams> diagnosticParamsCollection = ((DiagnosticsNotification) e.getCause()).getDiagnosticParamsCollection();
assertEquals(1, diagnosticParamsCollection.size());
PublishDiagnosticsParams diagnosticsParams = diagnosticParamsCollection.iterator().next();
List<Diagnostic> diagnostics = diagnosticsParams.getDiagnostics();
assertTrue(diagnostics.get(0).getMessage().contains("EOF"));
}
assertEquals("", surrogate.getEditorText());
}
Aggregations