From 24e5909ef159e37a104d142b928c84c0d8082d72 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 2 May 2018 11:35:44 -0400 Subject: [PATCH] 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. --- .../boot/java/utils/CompilationUnitCache.java | 4 ++-- .../boot/java/utils/SpringLiveHoverWatchdog.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/CompilationUnitCache.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/CompilationUnitCache.java index 3b89aaff8..351997c0d 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/CompilationUnitCache.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/CompilationUnitCache.java @@ -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 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(); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java index a46e5c29e..af3762c6b 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveHoverWatchdog.java @@ -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); }