6666@ SuppressWarnings ("restriction" )
6767public class LSPTextHover implements ITextHover , ITextHoverExtension , ITextHoverExtension2 {
6868
69+ private static final int GET_LEGACY_HOVER_INFO_TIMEOUT_MS = 1000 ;
70+ private static final int GET_ASYNC_HOVER_INFO_TIMEOUT_MS = 100 ;
6971 private static final int GET_HOVER_REGION_TIMEOUT_MS = 100 ;
7072
7173 private @ Nullable IRegion lastRegion ;
@@ -74,17 +76,17 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover
7476 private @ Nullable CompletableFuture <@ Nullable String > hoverInfoFuture ;
7577
7678 @ Override
79+ @ Deprecated
7780 public @ Nullable String getHoverInfo (ITextViewer textViewer , IRegion hoverRegion ) {
78- // Non-blocking: only return immediately available content.
7981 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- }
82+
83+ try {
84+ return hoverInfoRequest_ .get ( GET_LEGACY_HOVER_INFO_TIMEOUT_MS , TimeUnit . MILLISECONDS );
85+ } catch (InterruptedException ex ) {
86+ LanguageServerPlugin . logError (ex );
87+ Thread . currentThread (). interrupt ();
88+ } catch ( ExecutionException | TimeoutException ex ) {
89+ if (! CancellationUtil . isRequestCancelledException ( ex )) {
8890 LanguageServerPlugin .logError (ex );
8991 }
9092 }
@@ -94,8 +96,22 @@ public class LSPTextHover implements ITextHover, ITextHoverExtension, ITextHover
9496 @ Override
9597 public @ Nullable Object getHoverInfo2 (ITextViewer textViewer , IRegion hoverRegion ) {
9698 final var hoverInfoRequest_ = this .hoverInfoFuture = getHoverInfoFuture (textViewer , hoverRegion );
97- final String placeholder = "<html><body>Loading…</body></html>" ; //$NON-NLS-1$
98- return new AsyncHtmlHoverInput (hoverInfoRequest_ , placeholder );
99+
100+ try {
101+ return hoverInfoRequest_ .get (GET_ASYNC_HOVER_INFO_TIMEOUT_MS , TimeUnit .MILLISECONDS );
102+ } catch (InterruptedException ex ) {
103+ LanguageServerPlugin .logError (ex );
104+ Thread .currentThread ().interrupt ();
105+ return null ;
106+ } catch (ExecutionException ex ) {
107+ if (!CancellationUtil .isRequestCancelledException (ex )) {
108+ LanguageServerPlugin .logError (ex );
109+ }
110+ return null ;
111+ } catch (TimeoutException ex ) {
112+ final String placeholder = "<html><body>Loading…</body></html>" ; //$NON-NLS-1$
113+ return new AsyncHtmlHoverInput (hoverInfoRequest_ , placeholder );
114+ }
99115 }
100116
101117 public CompletableFuture <@ Nullable String > getHoverInfoFuture (ITextViewer textViewer , IRegion hoverRegion ) {
0 commit comments