Search in sources :

Example 6 with TextDocumentContentChangeEvent

use of org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent in project graal by oracle.

the class ParsingTest method checkChange.

private TextDocumentSurrogate checkChange(URI uri, Range range, String change, String editorText) throws InterruptedException, ExecutionException {
    TextDocumentContentChangeEvent event = TextDocumentContentChangeEvent.create(change).setRange(range).setRangeLength(change.length());
    Future<TextDocumentSurrogate> future = truffleAdapter.processChangesAndParse(Arrays.asList(event), uri);
    TextDocumentSurrogate surrogate = future.get();
    assertEquals(editorText, surrogate.getEditorText());
    assertSame(surrogate.getEditorText(), surrogate.getEditorText());
    return surrogate;
}
Also used : TextDocumentSurrogate(org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate) TextDocumentContentChangeEvent(org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent)

Example 7 with TextDocumentContentChangeEvent

use of org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent in project graal by oracle.

the class CompletionTest method replace.

private void replace(URI uri, Range range, String replacement, String diagMessage) throws InterruptedException {
    TextDocumentContentChangeEvent event = TextDocumentContentChangeEvent.create(replacement).setRange(range).setRangeLength(replacement.length());
    Future<?> future = truffleAdapter.processChangesAndParse(Arrays.asList(event), uri);
    try {
        future.get();
        assertNull(diagMessage);
    } catch (ExecutionException e) {
        assertFalse(diagMessage, diagMessage.isEmpty());
        Collection<PublishDiagnosticsParams> diagnosticParamsCollection = ((DiagnosticsNotification) e.getCause()).getDiagnosticParamsCollection();
        assertEquals(1, diagnosticParamsCollection.size());
        String message = diagnosticParamsCollection.iterator().next().getDiagnostics().get(0).getMessage();
        assertTrue(message, message.contains(diagMessage));
    }
}
Also used : Collection(java.util.Collection) ExecutionException(java.util.concurrent.ExecutionException) TextDocumentContentChangeEvent(org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent)

Aggregations

TextDocumentContentChangeEvent (org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent)7 Range (org.graalvm.tools.lsp.server.types.Range)2 Source (com.oracle.truffle.api.source.Source)1 URI (java.net.URI)1 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Position (org.graalvm.tools.lsp.server.types.Position)1 TextDocumentSurrogate (org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate)1 Test (org.junit.Test)1