PT 156688501 - Re-enable live hover optimisation

Live hovers are not published by the server if there are no running apps
in two consecutive update operations in the live hover watchdog. Also
fixed test cases that test no running apps.
This commit is contained in:
nsingh
2018-05-07 13:58:55 -07:00
parent ae531ff78c
commit 7f4967d0a6
5 changed files with 39 additions and 13 deletions

View File

@@ -209,8 +209,9 @@ public class Editor {
public List<Range> assertHighlights(String... expectedHighlights) throws Exception {
HighlightParams highlights = harness.getHighlights(doc);
List<Range> ranges = new ArrayList<>(highlights.getRanges());
HighlightParams highlights = expectedHighlights == null || expectedHighlights.length == 0 ? harness.getHighlights(false, doc)
: harness.getHighlights(doc);
List<Range> ranges = highlights != null ? new ArrayList<>(highlights.getRanges()) : ImmutableList.of();
Collections.sort(ranges, RANGE_COMPARATOR);
List<String> actualHighlights = ranges.stream()
.map(this::getText)
@@ -219,7 +220,6 @@ public class Editor {
return ranges;
}
/**
* Get the editor text, with cursor markers inserted (for easy textual comparison
* after applying a proposal)

View File

@@ -38,6 +38,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import org.assertj.core.api.Condition;
@@ -434,7 +435,32 @@ public class LanguageServerHarness<S extends SimpleLanguageServerWrapper> {
}
public HighlightParams getHighlights(TextDocumentInfo doc) throws Exception {
return getHighlightsFuture(doc).get(HIGHLIGHTS_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
return getHighlights(true, doc);
}
/**
* Set expectServerHighlights to false if NO highlights are expected from the server (for example, test cases
* that test that no highlights are received from the server because there are no running apps).
* @param expectServerHighlights false if NOT expecting any highlights from the server
* @param doc
* @return highlights, if they are expected, or null if they are not expected.
* @throws Exception
*/
public HighlightParams getHighlights(boolean expectServerHighlights, TextDocumentInfo doc) throws Exception {
try {
return getHighlightsFuture(doc).get(HIGHLIGHTS_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
// highlight requestor will timeout if the server does not send any highlights. This
// is not always an error. For example, if there are no initial running apps, the server will
// NOT send highlights (see PT 156688501), so in this case we expect to time out as part of
// the expected behaviour
if (!expectServerHighlights) {
return null;
}
else {
throw e;
}
}
}
public static Condition<Diagnostic> isDiagnosticWithSeverity(DiagnosticSeverity severity) {

View File

@@ -49,7 +49,7 @@ public class SpringLiveHoverWatchdog {
private RunningAppProvider runningAppProvider;
private boolean highlightsEnabled = true;
// private boolean hadPreviousRunningBootApps = false;
private boolean hadPreviousRunningBootApps = false;
private Timer timer;
@@ -157,17 +157,17 @@ public class SpringLiveHoverWatchdog {
publishLiveHints(docURI, ranges);
}
}
else
// if (this.hadPreviousRunningBootApps)
{
else if (this.hadPreviousRunningBootApps) {
// PT 156688501:
// Only clean up live hovers if there were running boot apps in the previous update, but not
// Only clean up live hovers if there were running boot apps in the previous
// update, but not
// in the current one.
// This is to avoid unnecessary publishing of live hovers when there have been no running apps
// This is to avoid unnecessary publishing of live hovers when there have been
// no running apps
// at all between consecutive updates.
cleanupLiveHints(docURI);
}
// this.hadPreviousRunningBootApps = hasCurrentRunningBootApps;
this.hadPreviousRunningBootApps = hasCurrentRunningBootApps;
} catch (Exception e) {
logger.error("", e);
}

View File

@@ -156,7 +156,7 @@ public class AutowiredHoverProviderTest {
"}\n"
);
editor.assertHighlights(/*MONE*/);
editor.assertHighlights(/*NONE*/);
editor.assertNoHover("@Autowired");
}

View File

@@ -471,7 +471,7 @@ public class ComponentInjectionsHoverProviderTest {
" }\n" +
"}\n"
);
editor.assertHighlights(/*MONE*/);
editor.assertHighlights(/*NONE*/);
editor.assertNoHover("@Component");
}