|
21 | 21 | import java.util.List; |
22 | 22 | import java.util.NoSuchElementException; |
23 | 23 | import java.util.Objects; |
| 24 | +import java.util.concurrent.CancellationException; |
24 | 25 | import java.util.concurrent.CompletableFuture; |
| 26 | +import java.util.concurrent.CompletionException; |
25 | 27 | import java.util.concurrent.ExecutionException; |
26 | 28 | import java.util.concurrent.TimeUnit; |
27 | 29 | import java.util.concurrent.TimeoutException; |
@@ -78,8 +80,13 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover |
78 | 80 | if (hoverInfoRequest_.isDone()) { |
79 | 81 | try { |
80 | 82 | 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); |
83 | 90 | } |
84 | 91 | } |
85 | 92 | return null; |
@@ -171,10 +178,12 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover |
171 | 178 | LSPEclipseUtils.toOffset(range.getEnd(), document)); |
172 | 179 | return this.lastRegion = new Region(regionStartOffset, regionEndOffset - regionStartOffset); |
173 | 180 | } 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 | + } |
175 | 184 | } catch (InterruptedException e) { |
176 | 185 | Thread.currentThread().interrupt(); |
177 | | - } catch (NoSuchElementException | TimeoutException e) { |
| 186 | + } catch (NoSuchElementException | TimeoutException | CancellationException e) { |
178 | 187 | // Fallback to heuristic region without blocking. |
179 | 188 | } |
180 | 189 |
|
|
0 commit comments