Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce public API and rename methods to have a name closer to its implementation #387

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public abstract class LanguageServers<E extends LanguageServers<E>> {
return getServers().stream()
.map(wrapperFuture -> wrapperFuture
.thenCompose(w -> w == null ? CompletableFuture.completedFuture((T) null) : w.executeImpl(ls -> fn.apply(w, ls))))
.reduce(init, LanguageServers::combine, LanguageServers::concatResults)
.reduce(init, LanguageServers::add, LanguageServers::addAll)

// Ensure any subsequent computation added by caller does not block further incoming messages from language servers
.thenApplyAsync(Function.identity());
Expand Down Expand Up @@ -293,15 +293,16 @@ public static <T> Stream<T> streamSafely(@Nullable Collection<T> col) {

/**
*
* Accumulator that appends the result of an async computation onto an async aggregate result. Nulls will be excluded.
* Combines the result of an async computation and an async list of results by adding the element to the list. Null elements will be excluded.
* @param <T> Result type
* @param result Async aggregate result
* @param next Pending result to include
* @param accumulator One async result
* @param element Another async result
* @return
*/
@SuppressWarnings("null")
@NonNull
public static <T> CompletableFuture<@NonNull List<@NonNull T>> combine(@NonNull CompletableFuture<? extends List<@NonNull T>> result, @NonNull CompletableFuture<@Nullable T> next) {
return result.thenCombine(next, (List<T> a, T b) -> {
private static <T> CompletableFuture<@NonNull List<@NonNull T>> add(@NonNull CompletableFuture<? extends @NonNull List<@NonNull T>> accumulator, @NonNull CompletableFuture<@Nullable T> element) {
return accumulator.thenCombine(element, (a, b) -> {
if (b != null) {
a.add(b);
}
Expand All @@ -310,17 +311,18 @@ public static <T> Stream<T> streamSafely(@Nullable Collection<T> col) {
}

/**
* Merges two async sets of results into a single async result
* Combines two async lists of results into a single list by adding all the elements of the second list to the first one.
* @param <T> Result type
* @param first First async result
* @param second Second async result
* @param accumulator One async result
* @param another Another async result
* @return Async combined result
*/
@SuppressWarnings("null")
@NonNull
public static <T> CompletableFuture<@NonNull List<T>> concatResults(@NonNull CompletableFuture<@NonNull List<T>> first, @NonNull CompletableFuture<@NonNull List<T>> second) {
return first.thenCombine(second, (c, d) -> {
c.addAll(d);
return c;
private static <T> CompletableFuture<@NonNull List<T>> addAll(@NonNull CompletableFuture<@NonNull List<T>> accumulator, @NonNull CompletableFuture<@NonNull List<T>> another) {
return accumulator.thenCombine(another, (a, b) -> {
a.addAll(b);
return a;
});
}

Expand Down