use of org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate in project graal by oracle.
the class TruffleAdapter method getLanguageId.
String getLanguageId(URI uri) {
TextDocumentSurrogate doc = surrogateMap.get(uri);
if (doc != null) {
return doc.getLanguageId();
}
Future<String> future = contextAwareExecutor.executeWithDefaultContext(() -> {
try {
return Source.findLanguage(envInternal.getTruffleFile(uri));
} catch (IOException ex) {
return null;
}
});
try {
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
use of org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate in project graal by oracle.
the class TruffleAdapter method parseWithEnteredContext.
protected CallTarget parseWithEnteredContext(final String text, final String langId, final URI uri) throws DiagnosticsNotification {
LanguageInfo languageInfo = findLanguageInfo(langId, envInternal.getTruffleFile(uri));
TextDocumentSurrogate surrogate = getOrCreateSurrogate(uri, text, languageInfo);
return parseWithEnteredContext(surrogate);
}
use of org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate in project graal by oracle.
the class TruffleAdapter method getOrCreateSurrogate.
TextDocumentSurrogate getOrCreateSurrogate(URI uri, String text, LanguageInfo languageInfo) {
TextDocumentSurrogate surrogate = surrogateMap.getOrCreateSurrogate(uri, languageInfo);
surrogate.setEditorText(text);
return surrogate;
}
use of org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate in project graal by oracle.
the class CompletionRequestHandler method fillCompletionsWithScopesValues.
private void fillCompletionsWithScopesValues(TextDocumentSurrogate surrogate, List<CompletionItem> completions, Object scopeOriginal, CompletionItemKind completionItemKindDefault, int displayPriority) {
LanguageInfo langInfo = surrogate.getLanguageInfo();
String[] existingCompletions = completions.stream().map((item) -> item.getLabel()).toArray(String[]::new);
// Filter duplicates
Set<String> completionKeys = new HashSet<>(Arrays.asList(existingCompletions));
int scopeCounter = 0;
Object scope = scopeOriginal;
while (scope != null) {
Object scopeParent = null;
if (INTEROP.hasScopeParent(scope)) {
try {
scopeParent = INTEROP.getScopeParent(scope);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
++scopeCounter;
Object keys;
long size;
try {
keys = INTEROP.getMembers(scope, false);
size = INTEROP.getArraySize(keys);
if (scopeParent != null) {
size -= INTEROP.getArraySize(INTEROP.getMembers(scopeParent, false));
}
} catch (Exception ex) {
logger.log(Level.INFO, ex.getLocalizedMessage(), ex);
break;
}
for (long i = 0; i < size; i++) {
String key;
Object object;
try {
key = INTEROP.asString(INTEROP.readArrayElement(keys, i));
if (completionKeys.contains(key)) {
// keys and only take those from the most inner scope
continue;
} else {
completionKeys.add(key);
}
object = INTEROP.readMember(scope, key);
} catch (ThreadDeath td) {
throw td;
} catch (Throwable t) {
logger.log(Level.CONFIG, scope.toString(), t);
continue;
}
CompletionItem completion = CompletionItem.create(key);
// Inner scopes should be displayed first, so sort by priority and scopeCounter
// (the innermost scope has the lowest counter)
completion.setSortText(String.format("%s%d.%04d.%s", "+", displayPriority, scopeCounter, key));
if (completionItemKindDefault != null) {
completion.setKind(completionItemKindDefault);
} else {
completion.setKind(findCompletionItemKind(object));
}
completion.setDetail(createCompletionDetail(object, langInfo));
try {
completion.setDocumentation(createDocumentation(object, surrogate.getLanguageInfo(), "in " + INTEROP.asString(INTEROP.toDisplayString(scope))));
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
completions.add(completion);
}
scope = scopeParent;
}
}
use of org.graalvm.tools.lsp.server.utils.TextDocumentSurrogate 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;
}
Aggregations