Avoid publishing live hints if there are no running apps
If there hasn't been a change in terms of no running apps between two consecutive updates, do not publish live hints to avoid unnecessary messages being sent from server to client.
This commit is contained in:
@@ -40,7 +40,7 @@ import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public final class CompilationUnitCache {
|
||||
|
||||
private static final long CU_ACCESS_EXPIRATION_MINUTES = 3;
|
||||
private static final long CU_ACCESS_EXPIRATION = 1;
|
||||
private JavaProjectFinder projectFinder;
|
||||
private ProjectObserver projectObserver;
|
||||
private Cache<URI, CompilationUnit> uriToCu;
|
||||
@@ -58,7 +58,7 @@ public final class CompilationUnitCache {
|
||||
// PT 154618835 - Avoid retaining the CU in the cache as it consumes memory if it hasn't been
|
||||
// accessed after some time
|
||||
uriToCu = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(CU_ACCESS_EXPIRATION_MINUTES, TimeUnit.MINUTES)
|
||||
.expireAfterWrite(CU_ACCESS_EXPIRATION, TimeUnit.MINUTES)
|
||||
.build();
|
||||
projectToDocs = CacheBuilder.newBuilder().build();
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public class SpringLiveHoverWatchdog {
|
||||
private RunningAppProvider runningAppProvider;
|
||||
|
||||
private boolean highlightsEnabled = true;
|
||||
private boolean hadPreviousRunningBootApps = false;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
@@ -148,17 +149,23 @@ public class SpringLiveHoverWatchdog {
|
||||
runningBootApps = runningAppProvider.getAllRunningSpringApps().toArray(new SpringBootApp[0]);
|
||||
}
|
||||
|
||||
if (runningBootApps != null && runningBootApps.length > 0) {
|
||||
boolean hasCurrentRunningBootApps = runningBootApps != null && runningBootApps.length > 0;
|
||||
if (hasCurrentRunningBootApps) {
|
||||
TextDocument doc = this.server.getTextDocumentService().get(docURI);
|
||||
if (doc != null) {
|
||||
Range[] ranges = this.hoverProvider.getLiveHoverHints(doc, runningBootApps);
|
||||
publishLiveHints(docURI, ranges);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (this.hadPreviousRunningBootApps) {
|
||||
// PT 156688501:
|
||||
// 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
|
||||
// at all between consecutive updates.
|
||||
cleanupLiveHints(docURI);
|
||||
}
|
||||
|
||||
this.hadPreviousRunningBootApps = hasCurrentRunningBootApps;
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user