|
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; |
25 | 26 | import java.util.concurrent.ExecutionException; |
26 | 27 | import java.util.concurrent.TimeUnit; |
|
48 | 49 | import org.eclipse.lsp4e.LSPEclipseUtils; |
49 | 50 | import org.eclipse.lsp4e.LanguageServerPlugin; |
50 | 51 | import org.eclipse.lsp4e.LanguageServers; |
| 52 | +import org.eclipse.lsp4e.internal.CancellationUtil; |
51 | 53 | import org.eclipse.lsp4j.Hover; |
52 | 54 | import org.eclipse.lsp4j.HoverParams; |
53 | 55 | import org.eclipse.lsp4j.MarkedString; |
@@ -78,8 +80,12 @@ 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 (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); |
83 | 89 | } |
84 | 90 | } |
85 | 91 | return null; |
@@ -171,10 +177,12 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover |
171 | 177 | LSPEclipseUtils.toOffset(range.getEnd(), document)); |
172 | 178 | return this.lastRegion = new Region(regionStartOffset, regionEndOffset - regionStartOffset); |
173 | 179 | } 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 | + } |
175 | 183 | } catch (InterruptedException e) { |
176 | 184 | Thread.currentThread().interrupt(); |
177 | | - } catch (NoSuchElementException | TimeoutException e) { |
| 185 | + } catch (NoSuchElementException | TimeoutException | CancellationException e) { |
178 | 186 | // Fallback to heuristic region without blocking. |
179 | 187 | } |
180 | 188 |
|
|
0 commit comments