use of org.springframework.ide.vscode.commons.util.Renderable in project sts4 by spring-projects.
the class PropertiesHoverCalculator method createRenderable.
private Renderable createRenderable(StsValueHint hint) {
Renderable description = hint.getDescription();
/*
* HACK: javadoc comment from HTML javadoc provider coming from
* generated HTML javadoc is very rich and decorating it further
* with some header like labels just makes it look worse
*/
if (description.toHtml().indexOf("<h") == -1) {
Builder<Renderable> renderableBuilder = ImmutableList.builder();
renderableBuilder.add(bold(text(hint.getValue())));
renderableBuilder.add(paragraph(description));
return concat(renderableBuilder.build());
} else {
return description;
}
}
use of org.springframework.ide.vscode.commons.util.Renderable in project sts4 by spring-projects.
the class RequestMappingHoverProvider method addHoverContent.
private void addHoverContent(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods, List<Either<String, MarkedString>> hoverContent) throws Exception {
for (int i = 0; i < mappingMethods.size(); i++) {
Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i);
SpringBootApp app = mappingMethod.getT2();
String port = mappingMethod.getT2().getPort();
String host = mappingMethod.getT2().getHost();
List<Renderable> renderableUrls = Arrays.stream(mappingMethod.getT1().getSplitPath()).flatMap(path -> {
String url = UrlUtil.createUrl(host, port, path);
StringBuilder builder = new StringBuilder();
builder.append("[");
builder.append(url);
builder.append("]");
builder.append("(");
builder.append(url);
builder.append(")");
return Stream.of(Renderables.text(builder.toString()), Renderables.lineBreak());
}).collect(Collectors.toList());
// Remove the last line break
renderableUrls.remove(renderableUrls.size() - 1);
hoverContent.add(Either.forLeft(Renderables.concat(renderableUrls).toMarkdown()));
hoverContent.add(Either.forLeft(LiveHoverUtils.niceAppName(app)));
if (i < mappingMethods.size() - 1) {
// Three dashes == line separator in Markdown
hoverContent.add(Either.forLeft("---"));
}
}
}
use of org.springframework.ide.vscode.commons.util.Renderable in project sts4 by spring-projects.
the class YPropertyInfoTemplates method createHover.
public static Renderable createHover(String contextProperty, YType contextType, YTypedProperty prop) {
Builder<Renderable> html = ImmutableList.builder();
if (StringUtil.hasText(contextProperty)) {
html.add(text(contextProperty));
html.add(text("."));
}
html.add(bold(text(prop.getName())));
html.add(lineBreak());
YType type = prop.getType();
if (type != null) {
html.add(link(type.toString(), /* no URL */
null));
}
Renderable description = prop.getDescription();
if (description != null) {
html.add(lineBreak());
html.add(lineBreak());
html.add(description);
}
return concat(html.build());
}
use of org.springframework.ide.vscode.commons.util.Renderable in project sts4 by spring-projects.
the class YamlHoverInfoProvider method getHoverInfo.
@Override
public Tuple2<Renderable, IRegion> getHoverInfo(IDocument doc, int offset) throws Exception {
YamlFileAST ast = getAst(doc);
if (ast != null) {
IRegion region = getHoverRegion(ast, offset);
if (region != null) {
YamlDocument ymlDoc = new YamlDocument(doc, structureProvider);
YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc);
if (assistContext != null) {
List<NodeRef<?>> astPath = ast.findPath(offset);
final YamlPath path = YamlPath.fromASTPath(astPath);
if (path != null) {
YamlPath assistPath = path;
if (assistPath.pointsAtKey()) {
// When a path points at a key we must tramsform it to a
// 'value-terminating path'
// to be able to reuse the 'getHoverInfo' method on
// YamlAssistContext (as navigation
// into 'key' is not defined for YamlAssistContext.
String key = path.getLastSegment().toPropString();
assistPath = path.dropLast().append(YamlPathSegment.valueAt(key));
}
assistContext = assistPath.traverse(assistContext);
if (assistContext != null) {
Renderable info = path.pointsAtValue() ? assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region)) : assistContext.getHoverInfo();
// Fix for: PT 134914895. If assist context cannot provide an info, then don't return a Tuple.
if (info != null) {
return Tuples.of(info, region);
}
}
}
}
}
}
return null;
}
Aggregations