additional optimization to avoid additional project identification on every live hover hint update

This commit is contained in:
Martin Lippert
2019-02-06 16:47:46 +01:00
parent f3b0f6a6de
commit 5bb448b0a0
3 changed files with 16 additions and 18 deletions

View File

@@ -99,13 +99,11 @@ public class BootJavaHoverProvider implements HoverHandler {
return SimpleTextDocumentService.NO_HOVER;
}
public CodeLens[] getLiveHoverHints(final TextDocument document, final SpringBootApp[] runningBootApps) {
public CodeLens[] getLiveHoverHints(final TextDocument document, IJavaProject project, final SpringBootApp[] runningBootApps) {
if (runningBootApps.length == 0) return new CodeLens[0];
if (project == null) return new CodeLens[0];
Optional<IJavaProject> project = getProject(document);
if (!project.isPresent()) return new CodeLens[0];
if (!hasActuatorDependency(project.get())) {
if (!hasActuatorDependency(project)) {
// double check the running apps in case there is a non-boot app running with live beans enabled
boolean nonBootLiveBeansAround = false;
boolean onAppsClasspath = false;
@@ -115,7 +113,7 @@ public class BootJavaHoverProvider implements HoverHandler {
break;
} else {
try {
List<File> binaryRoots = IClasspathUtil.getBinaryRoots(project.get().getClasspath(), Classpath::isSource);
List<File> binaryRoots = IClasspathUtil.getBinaryRoots(project.getClasspath(), Classpath::isSource);
for (String path : bootApp.getClasspath()) {
File file = new File(path);
if (binaryRoots.contains(file)) {
@@ -134,7 +132,7 @@ public class BootJavaHoverProvider implements HoverHandler {
}
}
return server.getCompilationUnitCache().withCompilationUnit(project.get(), URI.create(document.getUri()), cu -> {
return server.getCompilationUnitCache().withCompilationUnit(project, URI.create(document.getUri()), cu -> {
Collection<CodeLens> result = new LinkedHashSet<>();
try {
if (cu != null) {
@@ -143,7 +141,7 @@ public class BootJavaHoverProvider implements HoverHandler {
@Override
public boolean visit(TypeDeclaration node) {
try {
extractLiveHintsForType(node, document, project.get(), runningBootApps, result);
extractLiveHintsForType(node, document, project, runningBootApps, result);
}
catch (Exception e) {
logger.error("error extracting live hint information for docURI '" + document.getUri() + "' - on node: " + node.toString(), e);
@@ -154,7 +152,7 @@ public class BootJavaHoverProvider implements HoverHandler {
@Override
public boolean visit(SingleMemberAnnotation node) {
try {
extractLiveHintsForAnnotation(node, document, project.get(), runningBootApps, result);
extractLiveHintsForAnnotation(node, document, project, runningBootApps, result);
} catch (Exception e) {
logger.error("error extracting live hint information for docURI '" + document.getUri() + "' - on node: " + node.toString(), e);
}
@@ -165,7 +163,7 @@ public class BootJavaHoverProvider implements HoverHandler {
@Override
public boolean visit(NormalAnnotation node) {
try {
extractLiveHintsForAnnotation(node, document, project.get(), runningBootApps, result);
extractLiveHintsForAnnotation(node, document, project, runningBootApps, result);
} catch (Exception e) {
logger.error("error extracting live hint information for docURI '" + document.getUri() + "' - on node: " + node.toString(), e);
}
@@ -176,7 +174,7 @@ public class BootJavaHoverProvider implements HoverHandler {
@Override
public boolean visit(MarkerAnnotation node) {
try {
extractLiveHintsForAnnotation(node, document, project.get(), runningBootApps, result);
extractLiveHintsForAnnotation(node, document, project, runningBootApps, result);
} catch (Exception e) {
logger.error("error extracting live hint information for docURI '" + document.getUri() + "' - on node: " + node.toString(), e);
}
@@ -187,7 +185,7 @@ public class BootJavaHoverProvider implements HoverHandler {
@Override
public boolean visit(MethodDeclaration node) {
try {
extractLiveHintsForMethod(node, document, project.get(), runningBootApps, result);
extractLiveHintsForMethod(node, document, project, runningBootApps, result);
} catch (Exception e) {
logger.error("error extracting live hint information for docURI '" + document.getUri() + "' - on node: " + node.toString(), e);
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* Copyright (c) 2018, 2019 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -58,7 +58,7 @@ public class RunningAppMatcher {
public static boolean doesProjectNameMatch(SpringBootApp app, IJavaProject project) {
try {
String projectName = app.getSystemProperty("spring.boot.project.name");
return projectName != null && projectName.equals(project.getElementName());
return projectName != null && project != null && projectName.equals(project.getElementName());
}
catch (Exception e) {
return false;

View File

@@ -156,7 +156,7 @@ public class SpringLiveHoverWatchdog {
try {
IJavaProject project = getCachedProject(docURI);
SpringBootApp[] runningBootApps = RunningAppMatcher.getAllMatchingApps(runningAppProvider.getAllRunningSpringApps(), project).toArray(new SpringBootApp[0]);
update(docURI, runningBootApps);
update(docURI, project, runningBootApps);
}
catch (Exception e) {
logger.error("", e);
@@ -173,7 +173,7 @@ public class SpringLiveHoverWatchdog {
for (String docURI : watchedDocs.keySet()) {
IJavaProject project = getCachedProject(docURI);
SpringBootApp[] matchingApps = RunningAppMatcher.getAllMatchingApps(cachedApps, project).toArray(new SpringBootApp[0]);
update(docURI, matchingApps);
update(docURI, project, matchingApps);
}
this.hoverProvider.setRunningSpringApps(cachedApps);
@@ -185,14 +185,14 @@ public class SpringLiveHoverWatchdog {
}
// internal method, need to run on the scheduled executor pool, do not call outside of that
protected void update(String docURI, SpringBootApp[] runningBootApps) {
protected void update(String docURI, IJavaProject project, SpringBootApp[] runningBootApps) {
if (highlightsEnabled) {
try {
boolean hasCurrentRunningBootApps = runningBootApps != null && runningBootApps.length > 0;
if (hasCurrentRunningBootApps) {
TextDocument doc = this.server.getTextDocumentService().get(docURI);
if (doc != null) {
CodeLens[] infos = this.hoverProvider.getLiveHoverHints(doc, runningBootApps);
CodeLens[] infos = this.hoverProvider.getLiveHoverHints(doc, project, runningBootApps);
publishLiveHints(docURI, infos);
}
}