Search in sources :

Example 1 with PublishDiagnosticsParams

use of org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams 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()));
    }
}
Also used : PublishDiagnosticsParams(org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams) Collection(java.util.Collection) DiagnosticsNotification(org.graalvm.tools.lsp.exceptions.DiagnosticsNotification) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.Test)

Example 2 with PublishDiagnosticsParams

use of org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams 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());
}
Also used : TextDocumentSurrogate(org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate) PublishDiagnosticsParams(org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams) Collection(java.util.Collection) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.Test)

Example 3 with PublishDiagnosticsParams

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

the class ParsingTest method parseEOF.

@Test
public void parseEOF() throws InterruptedException {
    URI uri = createDummyFileUriForSL();
    String text = "function main";
    Future<?> future = truffleAdapter.parse(text, "sl", uri);
    try {
        future.get();
        fail();
    } catch (ExecutionException ex) {
        Collection<PublishDiagnosticsParams> diagnosticParams = ((DiagnosticsNotification) ex.getCause()).getDiagnosticParamsCollection();
        assertEquals(1, diagnosticParams.size());
        PublishDiagnosticsParams param = diagnosticParams.iterator().next();
        assertEquals(uri.toString(), param.getUri());
        List<Diagnostic> diagnostics = param.getDiagnostics();
        assertTrue(diagnostics.get(0).getMessage().contains("EOF"));
    }
}
Also used : PublishDiagnosticsParams(org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams) Collection(java.util.Collection) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)3 Collection (java.util.Collection)3 ExecutionException (java.util.concurrent.ExecutionException)3 PublishDiagnosticsParams (org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams)3 Test (org.junit.Test)3 List (java.util.List)2 DiagnosticsNotification (org.graalvm.tools.lsp.exceptions.DiagnosticsNotification)1 TextDocumentSurrogate (org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate)1