Skip to content

Commit

Permalink
fix: improve exception handling in InlayHintProvider (eclipse-lsp4e#1151
Browse files Browse the repository at this point in the history
)

If the request for an inlayHint() ends exceptionally, always return an empty list.

In addition, if the exception is due to a cancellation request, skip error logging. This is analogous to https://github.com/eclipse-lsp4e/lsp4e/blob/2f4198aa4bf739c76ab92eecdf891b889d7fc7cb/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java#L429-L436
  • Loading branch information
joaodinissf authored Dec 2, 2024
1 parent 2f4198a commit 53fc96a
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;

import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -26,6 +27,7 @@
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4e.internal.CancellationUtil;
import org.eclipse.lsp4j.InlayHint;
import org.eclipse.lsp4j.InlayHintParams;
import org.eclipse.lsp4j.Position;
Expand All @@ -49,7 +51,14 @@ public class InlayHintProvider extends AbstractCodeMiningProvider {
final var param = new InlayHintParams(LSPEclipseUtils.toTextDocumentIdentifier(docURI), viewPortRange);
List<LSPLineContentCodeMining> inlayHintResults = Collections.synchronizedList(new ArrayList<>());
return LanguageServers.forDocument(document).withCapability(ServerCapabilities::getInlayHintProvider)
.collectAll((w, ls) -> ls.getTextDocumentService().inlayHint(param).thenAcceptAsync(inlayHints -> {
.collectAll((w, ls) -> ls.getTextDocumentService() //
.inlayHint(param).exceptionally((ex -> {
if (!(ex instanceof CancellationException || CancellationUtil.isRequestCancelledException(ex))) {
LanguageServerPlugin.logError(ex);
}
return Collections.emptyList();
})) //
.thenAcceptAsync(inlayHints -> {
// textDocument/inlayHint may return null
if (inlayHints != null) {
inlayHints.stream().filter(Objects::nonNull)
Expand Down

0 comments on commit 53fc96a

Please sign in to comment.