Startup time for beans in CodeLenses

This commit is contained in:
BoykoAlex
2020-11-24 11:28:07 -05:00
parent 6704262899
commit 824832b2d9
3 changed files with 47 additions and 12 deletions

View File

@@ -105,6 +105,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
protected List<CodeLens> assembleCodeLenses(IJavaProject project, SpringProcessLiveData[] processLiveData, DefinedBeanProvider definedBeanProvider,
TextDocument doc, Range range, ASTNode node) {
List<CodeLens> codeLenses = null;
boolean beanFound = false;
for (SpringProcessLiveData liveData : processLiveData) {
@@ -112,9 +113,9 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
if (definedBean == null) {
continue;
}
beanFound = true;
beanFound = true;
List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(liveData, definedBean);
if (!relevantBeans.isEmpty()) {
@@ -131,13 +132,28 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
// Wired beans code lenses
List<LiveBean> wiredBeans = findWiredBeans(project, liveData, relevantBeans, node);
builder.addAll(assembleCodeLenseForAutowired(wiredBeans, project, liveData, doc, range, node));
// Startup metrics CodeLens
if (liveData.getStartupMetrics() != null) {
Duration startupTime = liveData.getStartupMetrics().getBeanInstanciationTime(definedBean.getId());
if (startupTime != null) {
builder.add(LiveHoverUtils.createCodeLenseForBeanStartupMetric(range, startupTime));
}
}
List<CodeLens> codeLenses = builder.build();
return codeLenses.isEmpty() ? ImmutableList.of(new CodeLens(range)) : codeLenses;
// If Injected into and Wired beans are found for an app just return ocde lenses for the bean from the app
codeLenses = builder.build();
break;
} else if (liveData.getStartupMetrics() != null && liveData.getStartupMetrics().getBeanInstanciationTime(definedBean.getId()) != null) {
Duration startupTime = liveData.getStartupMetrics().getBeanInstanciationTime(definedBean.getId());
codeLenses = ImmutableList.of(LiveHoverUtils.createCodeLenseForBeanStartupMetric(range, startupTime));
}
}
return beanFound ? ImmutableList.of(new CodeLens(range)) : null;
if (beanFound) {
return codeLenses == null || codeLenses.isEmpty() ? ImmutableList.of(new CodeLens(range)) : codeLenses;
}
return null;
}
protected List<CodeLens> assembleCodeLenseForAutowired(List<LiveBean> wiredBeans, IJavaProject project, SpringProcessLiveData processLiveData, TextDocument doc, Range nameRange, ASTNode astNode) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Pivotal, Inc.
* Copyright (c) 2017, 2020 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.livehover;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -210,6 +211,21 @@ public class LiveHoverUtils {
}
}
public static CodeLens createCodeLenseForBeanStartupMetric(Range range, Duration startupTime) {
CodeLens codeLens = new CodeLens();
codeLens.setRange(range);
StringBuilder sb = new StringBuilder("Startup: ");
sb.append(startupTime.toMillis());
sb.append("ms");
codeLens.setData(sb.toString());
Command cmd = new Command();
cmd.setTitle(sb.toString());
cmd.setCommand("sts.showHoverAtPosition");
cmd.setArguments(ImmutableList.of(range.getStart()));
codeLens.setCommand(cmd);
return codeLens;
}
@SuppressWarnings("unchecked")
public static List<CodeLens> createCodeLensForMethodParameters(SpringProcessLiveData liveData, IJavaProject project, MethodDeclaration method, TextDocument doc, List<LiveBean> wiredBeans) {

View File

@@ -260,7 +260,9 @@ public class RequestMappingHoverProvider implements HoverProvider {
}
for (String path : paths) {
String url = UrlUtil.createUrl(urlScheme, host, port, path, contextPath);
urls.add(Tuples.of(url, path));
if (url != null) {
urls.add(Tuples.of(url, path));
}
}
return urls;
}
@@ -360,26 +362,27 @@ public class RequestMappingHoverProvider implements HoverProvider {
return metricsContent.toString();
}
private CodeLens createCodeLensForRequestMapping(Range range, String content, RequestMappingMetrics metrics) {
private CodeLens createCodeLensForRequestMapping(Range range, String url, RequestMappingMetrics metrics) {
CodeLens codeLens = new CodeLens();
codeLens.setRange(range);
Command cmd = new Command();
if (StringUtil.hasText(content)) {
if (StringUtil.hasText(url)) {
StringBuilder codeLensContent = new StringBuilder(url);
if (metrics != null) {
StringBuilder codeLensContent = new StringBuilder(content);
codeLensContent.append(' ');
codeLensContent.append('(');
codeLensContent.append(createCodeLensMetricsContent(metrics));
codeLensContent.append(')');
content = codeLensContent.toString();
}
String content = codeLensContent.toString();
codeLens.setData(content);
cmd.setTitle(content);
cmd.setCommand("sts.open.url");
cmd.setArguments(ImmutableList.of(content));
cmd.setArguments(ImmutableList.of(url));
}
codeLens.setCommand(cmd);