Skip to content

Commit f272d5a

Browse files
committed
fix: reduce LSPTextHover resize flicker
1 parent 8747384 commit f272d5a

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

org.eclipse.lsp4e/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: Language Server Protocol client for Eclipse IDE (Incubation)
44
Bundle-SymbolicName: org.eclipse.lsp4e;singleton:=true
5-
Bundle-Version: 0.19.3.qualifier
5+
Bundle-Version: 0.19.4.qualifier
66
Bundle-RequiredExecutionEnvironment: JavaSE-21
77
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
88
org.eclipse.equinox.common;bundle-version="3.8.0",

org.eclipse.lsp4e/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<artifactId>org.eclipse.lsp4e</artifactId>
1212
<packaging>eclipse-plugin</packaging>
13-
<version>0.19.3-SNAPSHOT</version>
13+
<version>0.19.4-SNAPSHOT</version>
1414

1515
<build>
1616
<plugins>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void updateBrowserSize(final Browser browser) {
103103
setSize(hint.x, hint.y);
104104

105105
if (!"complete".equals(safeEvaluate(browser, "return document.readyState"))) { //$NON-NLS-1$ //$NON-NLS-2$
106-
UI.getDisplay().timerExec(200, () -> updateBrowserSize(browser));
106+
UI.getDisplay().timerExec(50, () -> updateBrowserSize(browser));
107107
return;
108108
}
109109

@@ -191,6 +191,7 @@ public void setInput(@Nullable Object input) {
191191
}));
192192
return;
193193
}
194+
this.currentAsyncToken = null;
194195
if (input instanceof String html) {
195196
input = styleHtml(html);
196197
}

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
@SuppressWarnings("restriction")
6767
public 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

Comments
 (0)