Skip to content

Commit 497a15c

Browse files
authored
fix: treat cancelled hover requests as non-errors (#1442)
Fixes #1441
1 parent 4e5c4a9 commit 497a15c

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.jface.util.Util;
2727
import org.eclipse.lsp4e.LSPEclipseUtils;
2828
import org.eclipse.lsp4e.LanguageServerPlugin;
29+
import org.eclipse.lsp4e.internal.CancellationUtil;
2930
import org.eclipse.lsp4e.ui.UI;
3031
import org.eclipse.swt.browser.Browser;
3132
import org.eclipse.swt.browser.LocationEvent;
@@ -171,6 +172,11 @@ public void setInput(@Nullable Object input) {
171172
return; // input changed; ignore stale update
172173
}
173174
if (ex != null) {
175+
if (CancellationUtil.isRequestCancelledException(ex)) {
176+
// Hover request was cancelled; treat as benign and hide placeholder.
177+
super.setInput(""); //$NON-NLS-1$
178+
return;
179+
}
174180
LanguageServerPlugin.logError(ex);
175181
super.setInput(
176182
"Unexpected error: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage()); //$NON-NLS-1$ //$NON-NLS-2$

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/LSPTextHover.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.NoSuchElementException;
2323
import java.util.Objects;
24+
import java.util.concurrent.CancellationException;
2425
import java.util.concurrent.CompletableFuture;
2526
import java.util.concurrent.ExecutionException;
2627
import java.util.concurrent.TimeUnit;
@@ -48,6 +49,7 @@
4849
import org.eclipse.lsp4e.LSPEclipseUtils;
4950
import org.eclipse.lsp4e.LanguageServerPlugin;
5051
import org.eclipse.lsp4e.LanguageServers;
52+
import org.eclipse.lsp4e.internal.CancellationUtil;
5153
import org.eclipse.lsp4j.Hover;
5254
import org.eclipse.lsp4j.HoverParams;
5355
import org.eclipse.lsp4j.MarkedString;
@@ -78,8 +80,12 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover
7880
if (hoverInfoRequest_.isDone()) {
7981
try {
8082
return hoverInfoRequest_.getNow(null);
81-
} catch (Exception e) {
82-
LanguageServerPlugin.logError(e);
83+
} catch (final Exception ex) {
84+
if (CancellationUtil.isRequestCancelledException(ex)) {
85+
// Hover was cancelled; ignore as this is an expected fast-mouse-move scenario.
86+
return null;
87+
}
88+
LanguageServerPlugin.logError(ex);
8389
}
8490
}
8591
return null;
@@ -171,10 +177,12 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover
171177
LSPEclipseUtils.toOffset(range.getEnd(), document));
172178
return this.lastRegion = new Region(regionStartOffset, regionEndOffset - regionStartOffset);
173179
} catch (ExecutionException | BadLocationException e) {
174-
LanguageServerPlugin.logError("Cannot get hover region for offset " + offset, e); //$NON-NLS-1$
180+
if (!CancellationUtil.isRequestCancelledException(e)) {
181+
LanguageServerPlugin.logError("Cannot get hover region for offset " + offset, e); //$NON-NLS-1$
182+
}
175183
} catch (InterruptedException e) {
176184
Thread.currentThread().interrupt();
177-
} catch (NoSuchElementException | TimeoutException e) {
185+
} catch (NoSuchElementException | TimeoutException | CancellationException e) {
178186
// Fallback to heuristic region without blocking.
179187
}
180188

0 commit comments

Comments
 (0)