6767public class LSPTextHover implements ITextHover , ITextHoverExtension , ITextHoverExtension2 {
6868
6969 private static final int GET_HOVER_REGION_TIMEOUT_MS = 100 ;
70+ private static final int GET_HOVER_INFO_TIMEOUT_MS = 100 ;
7071
7172 private @ Nullable IRegion lastRegion ;
7273 private @ Nullable ITextViewer lastViewer ;
@@ -75,24 +76,29 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover
7576
7677 @ Override
7778 public @ Nullable String getHoverInfo (ITextViewer textViewer , IRegion hoverRegion ) {
78- // Non-blocking: only return immediately available content.
7979 final var hoverInfoRequest_ = this .hoverInfoFuture = getHoverInfoFuture (textViewer , hoverRegion );
80- if (hoverInfoRequest_ .isDone ()) {
81- try {
82- return hoverInfoRequest_ .getNow (null );
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 );
80+ try {
81+ return hoverInfoRequest_ .get (GET_HOVER_INFO_TIMEOUT_MS , TimeUnit .MILLISECONDS );
82+ } catch (InterruptedException ex ) {
83+ LanguageServerPlugin .logError (ex );
84+ Thread .currentThread ().interrupt ();
85+ return null ;
86+ } catch (ExecutionException | TimeoutException ex ) {
87+ if (CancellationUtil .isRequestCancelledException (ex )) {
88+ // Hover was cancelled; ignore as this is an expected fast-mouse-move scenario.
89+ return null ;
8990 }
91+ LanguageServerPlugin .logError (ex );
9092 }
9193 return null ;
9294 }
9395
9496 @ Override
9597 public @ Nullable Object getHoverInfo2 (ITextViewer textViewer , IRegion hoverRegion ) {
98+ final var hoverInfo = getHoverInfo (textViewer , hoverRegion );
99+ if (hoverInfo != null )
100+ return hoverInfo ;
101+
96102 final var hoverInfoRequest_ = this .hoverInfoFuture = getHoverInfoFuture (textViewer , hoverRegion );
97103 final String placeholder = "<html><body>Loading…</body></html>" ; //$NON-NLS-1$
98104 return new AsyncHtmlHoverInput (hoverInfoRequest_ , placeholder );
0 commit comments