use of org.graalvm.tools.lsp.server.types.CompletionItem 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());
}
use of org.graalvm.tools.lsp.server.types.CompletionItem 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());
}
use of org.graalvm.tools.lsp.server.types.CompletionItem 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();
}
use of org.graalvm.tools.lsp.server.types.CompletionItem in project graal by oracle.
the class CompletionRequestHandler method fillCompletionsFromTruffleObject.
protected boolean fillCompletionsFromTruffleObject(List<CompletionItem> completions, LanguageInfo langInfo, Object object) {
if (object == null) {
return false;
}
Object metaObject = getMetaObject(langInfo, object);
if (metaObject == null) {
return false;
}
Object languageView = env.getLanguageView(langInfo, object);
Object members = null;
if (INTEROP.hasMembers(languageView)) {
try {
members = INTEROP.getMembers(languageView);
} catch (UnsupportedMessageException ex) {
// No members
}
}
if (members == null || !INTEROP.hasArrayElements(members)) {
logger.fine("No completions found for object: " + languageView);
return false;
}
int counter = 0;
long size;
try {
size = INTEROP.getArraySize(members);
} catch (UnsupportedMessageException ex) {
size = 0;
}
for (long i = 0; i < size; i++) {
String key;
Object value;
try {
key = INTEROP.readArrayElement(members, i).toString();
if (INTEROP.isMemberReadable(languageView, key)) {
value = INTEROP.readMember(languageView, key);
} else {
value = null;
}
} catch (ThreadDeath td) {
throw td;
} catch (Throwable t) {
logger.log(Level.CONFIG, languageView.toString(), t);
continue;
}
CompletionItem completion = CompletionItem.create(key);
++counter;
// Keep the order in which the keys were provided
completion.setSortText(String.format("%s%06d.%s", "+", counter, key));
completion.setKind(CompletionItemKind.Property);
completion.setDetail(createCompletionDetail(value, langInfo));
try {
completion.setDocumentation(createDocumentation(value, langInfo, "of " + INTEROP.getMetaQualifiedName(metaObject)));
} catch (UnsupportedMessageException e) {
throw new AssertionError(e);
}
completions.add(completion);
}
return counter > 0;
}
use of org.graalvm.tools.lsp.server.types.CompletionItem 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);
}
}
Aggregations