|
17 | 17 |
|
18 | 18 | import java.net.URI; |
19 | 19 | import java.time.Duration; |
20 | | -import java.util.ArrayList; |
21 | 20 | import java.util.HashMap; |
22 | 21 | import java.util.List; |
23 | 22 | import java.util.Map.Entry; |
| 23 | +import java.util.Objects; |
24 | 24 | import java.util.concurrent.CompletableFuture; |
25 | 25 |
|
26 | 26 | import org.eclipse.core.runtime.ICoreRunnable; |
@@ -84,7 +84,7 @@ public class HighlightReconcilingStrategy |
84 | 84 | private static final int HIGHLIGHT_DEBOUNCE_MS = 75; |
85 | 85 |
|
86 | 86 | // Short-lived cache for highlights per document+normalized offset. |
87 | | - private static final DocumentOffsetAsyncCache<List<DocumentHighlight>> HIGHLIGHT_CACHE = |
| 87 | + private static final DocumentOffsetAsyncCache<List<? extends DocumentHighlight>> HIGHLIGHT_CACHE = |
88 | 88 | new DocumentOffsetAsyncCache<>(Duration.ofSeconds(10)); |
89 | 89 |
|
90 | 90 | // Track the last normalized cache key to avoid canceling identical in-flight work. |
@@ -229,28 +229,14 @@ private void collectHighlights(int caretOffset, @Nullable IProgressMonitor monit |
229 | 229 | final var params = new DocumentHighlightParams(identifier, position); |
230 | 230 |
|
231 | 231 | // Use cache to deduplicate requests to the same symbol for a short period. |
232 | | - final CompletableFuture<List<DocumentHighlight>> request = HIGHLIGHT_CACHE.computeIfAbsent(document, |
| 232 | + final CompletableFuture<List<? extends DocumentHighlight>> request = HIGHLIGHT_CACHE.computeIfAbsent(document, |
233 | 233 | cacheKeyOffset, () -> { |
234 | | - final var reqs = requests = LanguageServers.forDocument(document) |
235 | | - .withCapability(ServerCapabilities::getDocumentHighlightProvider) |
236 | | - .computeAll(ls -> ls.getTextDocumentService().documentHighlight(params)); |
237 | | - final CompletableFuture<?> all = CompletableFuture |
238 | | - .allOf(reqs.stream().map(f -> (CompletableFuture<?>) f).toArray(CompletableFuture[]::new)); |
239 | | - return all.thenApply(unused -> { |
240 | | - final var allHighlights = new ArrayList<DocumentHighlight>(); |
241 | | - for (final var req : reqs) { |
242 | | - try { |
243 | | - final List<? extends DocumentHighlight> highlight = req.join(); |
244 | | - if (highlight != null) { |
245 | | - allHighlights.addAll(highlight); |
246 | | - } |
247 | | - } catch (Exception ex) { |
248 | | - // ignore single-server failures |
249 | | - } |
250 | | - } |
251 | | - return allHighlights; |
| 234 | + final var reqs = requests = LanguageServers.forDocument(document) |
| 235 | + .withCapability(ServerCapabilities::getDocumentHighlightProvider) |
| 236 | + .computeAll(ls -> ls.getTextDocumentService().documentHighlight(params)); |
| 237 | + return CompletableFuture.supplyAsync(() -> reqs.stream().map(CompletableFuture::join) // |
| 238 | + .filter(Objects::nonNull).flatMap(List::stream).toList()); |
252 | 239 | }); |
253 | | - }); |
254 | 240 |
|
255 | 241 | request.thenAcceptAsync(highlights -> { |
256 | 242 | if (monitor == null || !monitor.isCanceled()) { |
|
0 commit comments