Search in sources :

Example 1 with CompletionList

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

the class CompletionTest method objectPropertyCompletionViaCoverageData.

@Test
public void objectPropertyCompletionViaCoverageData() throws InterruptedException, ExecutionException {
    URI uri = createDummyFileUriForSL();
    Future<?> future = truffleAdapter.parse(PROG_OBJ_NOT_CALLED, "sl", uri);
    future.get();
    Future<Boolean> futureCoverage = truffleAdapter.runCoverageAnalysis(uri);
    futureCoverage.get();
    setTriggerCharacters();
    replace(uri, Range.create(Position.create(8, 12), Position.create(8, 12)), ".", "extraneous input '.'");
    Future<CompletionList> futureC = truffleAdapter.completion(uri, 8, 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());
}
Also used : CompletionList(org.graalvm.tools.lsp.server.types.CompletionList) CompletionItem(org.graalvm.tools.lsp.server.types.CompletionItem) URI(java.net.URI) Test(org.junit.Test)

Example 2 with CompletionList

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

the class CompletionTest method checkEmpty.

private void checkEmpty(URI uri, int line, int column) throws InterruptedException, ExecutionException {
    Future<CompletionList> futureCompletions = truffleAdapter.completion(uri, line, column, null);
    CompletionList completionList = futureCompletions.get();
    assertFalse(completionList.isIncomplete());
    List<CompletionItem> items = completionList.getItems();
    assertTrue(items.isEmpty());
}
Also used : CompletionList(org.graalvm.tools.lsp.server.types.CompletionList) CompletionItem(org.graalvm.tools.lsp.server.types.CompletionItem)

Example 3 with CompletionList

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

the class CompletionTest method checkGlobalsAndLocals.

private int checkGlobalsAndLocals(URI uri, int line, int column, int numberOfGlobalsItems, Object... vars) throws InterruptedException, ExecutionException {
    Future<CompletionList> futureCompletions = truffleAdapter.completion(uri, line, column, null);
    CompletionList completionList = futureCompletions.get();
    assertFalse(completionList.isIncomplete());
    List<CompletionItem> items = completionList.getItems();
    assertFalse(items.isEmpty());
    NodeInfo nodeInfo = SLLanguage.lookupNodeInfo(SLHelloEqualsWorldBuiltin.class);
    assertNotNull(nodeInfo);
    String shortName = nodeInfo.shortName();
    assertTrue("Built-in function " + shortName + " not found.", items.stream().anyMatch(item -> item.getLabel().startsWith(shortName)));
    for (int i = 0; i < vars.length; i += 2) {
        String var = (String) vars[i];
        boolean present = (boolean) vars[i + 1];
        if (present) {
            assertTrue(var + " should be found in function scope", items.stream().anyMatch(item -> item.getLabel().startsWith(var)));
        } else {
            assertTrue(var + " should not be found in main-function scope", items.stream().noneMatch(item -> item.getLabel().startsWith(var)));
        }
    }
    if (numberOfGlobalsItems != -1) {
        assertEquals(numberOfGlobalsItems, items.size());
    }
    return items.size();
}
Also used : Arrays(java.util.Arrays) Position(org.graalvm.tools.lsp.server.types.Position) NodeInfo(com.oracle.truffle.api.nodes.NodeInfo) Future(java.util.concurrent.Future) CompletionList(org.graalvm.tools.lsp.server.types.CompletionList) SLLanguage(com.oracle.truffle.sl.SLLanguage) CompletionItemKind(org.graalvm.tools.lsp.server.types.CompletionItemKind) PublishDiagnosticsParams(org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams) DiagnosticsNotification(org.graalvm.tools.lsp.exceptions.DiagnosticsNotification) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) ServerCapabilities(org.graalvm.tools.lsp.server.types.ServerCapabilities) CompletionItem(org.graalvm.tools.lsp.server.types.CompletionItem) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) TextDocumentContentChangeEvent(org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Range(org.graalvm.tools.lsp.server.types.Range) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) CompletionOptions(org.graalvm.tools.lsp.server.types.CompletionOptions) SLHelloEqualsWorldBuiltin(com.oracle.truffle.sl.builtins.SLHelloEqualsWorldBuiltin) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CompletionList(org.graalvm.tools.lsp.server.types.CompletionList) CompletionItem(org.graalvm.tools.lsp.server.types.CompletionItem) NodeInfo(com.oracle.truffle.api.nodes.NodeInfo)

Example 4 with CompletionList

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

Aggregations

CompletionItem (org.graalvm.tools.lsp.server.types.CompletionItem)4 CompletionList (org.graalvm.tools.lsp.server.types.CompletionList)4 URI (java.net.URI)3 Test (org.junit.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 DiagnosticsNotification (org.graalvm.tools.lsp.exceptions.DiagnosticsNotification)2 NodeInfo (com.oracle.truffle.api.nodes.NodeInfo)1 SLLanguage (com.oracle.truffle.sl.SLLanguage)1 SLHelloEqualsWorldBuiltin (com.oracle.truffle.sl.builtins.SLHelloEqualsWorldBuiltin)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 CompletionItemKind (org.graalvm.tools.lsp.server.types.CompletionItemKind)1 CompletionOptions (org.graalvm.tools.lsp.server.types.CompletionOptions)1 Position (org.graalvm.tools.lsp.server.types.Position)1 PublishDiagnosticsParams (org.graalvm.tools.lsp.server.types.PublishDiagnosticsParams)1 Range (org.graalvm.tools.lsp.server.types.Range)1 ServerCapabilities (org.graalvm.tools.lsp.server.types.ServerCapabilities)1