Skip to content

Commit 16702a7

Browse files
committed
fix: treat cancelled hover requests as non-errors
1 parent 4e5c4a9 commit 16702a7

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import java.net.URL;
1616
import java.util.UUID;
17+
import java.util.concurrent.CancellationException;
18+
import java.util.concurrent.CompletionException;
1719

1820
import org.eclipse.core.runtime.FileLocator;
1921
import org.eclipse.core.runtime.Platform;
@@ -171,6 +173,12 @@ public void setInput(@Nullable Object input) {
171173
return; // input changed; ignore stale update
172174
}
173175
if (ex != null) {
176+
if (ex instanceof CancellationException || (ex instanceof CompletionException ce
177+
&& ce.getCause() instanceof CancellationException)) {
178+
// Hover request was cancelled; treat as benign and hide placeholder.
179+
super.setInput(""); //$NON-NLS-1$
180+
return;
181+
}
174182
LanguageServerPlugin.logError(ex);
175183
super.setInput(
176184
"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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
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;
26+
import java.util.concurrent.CompletionException;
2527
import java.util.concurrent.ExecutionException;
2628
import java.util.concurrent.TimeUnit;
2729
import java.util.concurrent.TimeoutException;
@@ -78,8 +80,13 @@ 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 (ex instanceof CancellationException
85+
|| (ex instanceof CompletionException ce && ce.getCause() instanceof CancellationException)) {
86+
// Hover was cancelled; ignore as this is an expected fast-mouse-move scenario.
87+
return null;
88+
}
89+
LanguageServerPlugin.logError(ex);
8390
}
8491
}
8592
return null;
@@ -171,10 +178,12 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover
171178
LSPEclipseUtils.toOffset(range.getEnd(), document));
172179
return this.lastRegion = new Region(regionStartOffset, regionEndOffset - regionStartOffset);
173180
} catch (ExecutionException | BadLocationException e) {
174-
LanguageServerPlugin.logError("Cannot get hover region for offset " + offset, e); //$NON-NLS-1$
181+
if (!(e.getCause() instanceof CancellationException)) {
182+
LanguageServerPlugin.logError("Cannot get hover region for offset " + offset, e); //$NON-NLS-1$
183+
}
175184
} catch (InterruptedException e) {
176185
Thread.currentThread().interrupt();
177-
} catch (NoSuchElementException | TimeoutException e) {
186+
} catch (NoSuchElementException | TimeoutException | CancellationException e) {
178187
// Fallback to heuristic region without blocking.
179188
}
180189

0 commit comments

Comments
 (0)