diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java index e58bad99f..f2d0dde8e 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServers.java @@ -70,7 +70,7 @@ public abstract class LanguageServers> { 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()); @@ -293,15 +293,16 @@ public static Stream streamSafely(@Nullable Collection 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 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 CompletableFuture<@NonNull List<@NonNull T>> combine(@NonNull CompletableFuture> result, @NonNull CompletableFuture<@Nullable T> next) { - return result.thenCombine(next, (List a, T b) -> { + private static CompletableFuture<@NonNull List<@NonNull T>> add(@NonNull CompletableFuture> accumulator, @NonNull CompletableFuture<@Nullable T> element) { + return accumulator.thenCombine(element, (a, b) -> { if (b != null) { a.add(b); } @@ -310,17 +311,18 @@ public static Stream streamSafely(@Nullable Collection 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 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 CompletableFuture<@NonNull List> concatResults(@NonNull CompletableFuture<@NonNull List> first, @NonNull CompletableFuture<@NonNull List> second) { - return first.thenCombine(second, (c, d) -> { - c.addAll(d); - return c; + private static CompletableFuture<@NonNull List> addAll(@NonNull CompletableFuture<@NonNull List> accumulator, @NonNull CompletableFuture<@NonNull List> another) { + return accumulator.thenCombine(another, (a, b) -> { + a.addAll(b); + return a; }); }