Search in sources :

Example 6 with Renderable

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;
    }
}
Also used : Renderable(org.springframework.ide.vscode.commons.util.Renderable)

Example 7 with Renderable

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("---"));
        }
    }
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Arrays(java.util.Arrays) IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) Range(org.eclipse.lsp4j.Range) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) HoverProvider(org.springframework.ide.vscode.boot.java.handlers.HoverProvider) Annotation(org.eclipse.jdt.core.dom.Annotation) ImmutableList(com.google.common.collect.ImmutableList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Log(org.springframework.ide.vscode.commons.util.Log) LiveHoverUtils(org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils) Collection(java.util.Collection) MarkedString(org.eclipse.lsp4j.MarkedString) Renderables(org.springframework.ide.vscode.commons.util.Renderables) Collectors(java.util.stream.Collectors) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) List(java.util.List) Stream(java.util.stream.Stream) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MarkedString(org.eclipse.lsp4j.MarkedString) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping)

Example 8 with Renderable

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());
}
Also used : Renderable(org.springframework.ide.vscode.commons.util.Renderable) YType(org.springframework.ide.vscode.commons.yaml.schema.YType)

Example 9 with Renderable

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;
}
Also used : NodeRef(org.springframework.ide.vscode.commons.yaml.ast.NodeRef) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) Renderable(org.springframework.ide.vscode.commons.util.Renderable) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) YamlDocument(org.springframework.ide.vscode.commons.yaml.structure.YamlDocument) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) YamlAssistContext(org.springframework.ide.vscode.commons.yaml.completion.YamlAssistContext) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Aggregations

Renderable (org.springframework.ide.vscode.commons.util.Renderable)9 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)3 IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)3 ImmutableList (com.google.common.collect.ImmutableList)2 Collection (java.util.Collection)2 Hover (org.eclipse.lsp4j.Hover)2 Range (org.eclipse.lsp4j.Range)2 Deprecation (org.springframework.ide.vscode.boot.configurationmetadata.Deprecation)2 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)2 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)2 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)2 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)2 Tuple2 (reactor.util.function.Tuple2)2 Tuples (reactor.util.function.Tuples)2 Builder (com.google.common.collect.ImmutableList.Builder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1