Search in sources :

Example 6 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class LiveAppURLSymbolProvider method getSymbols.

public List<? extends SymbolInformation> getSymbols(String query) {
    System.out.println(query);
    List<SymbolInformation> result = new ArrayList<>();
    try {
        SpringBootApp[] runningApps = runningAppProvider.getAllRunningSpringApps().toArray(new SpringBootApp[0]);
        for (SpringBootApp app : runningApps) {
            try {
                String host = app.getHost();
                String port = app.getPort();
                Stream<String> urls = app.getRequestMappings().stream().flatMap(rm -> Arrays.stream(rm.getSplitPath())).map(path -> UrlUtil.createUrl(host, port, path));
                urls.forEach(url -> result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))));
            } catch (Exception e) {
                Log.log(e);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return result;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) RunningAppProvider(org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) Log(org.springframework.ide.vscode.commons.util.Log) SymbolKind(org.eclipse.lsp4j.SymbolKind) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Location(org.eclipse.lsp4j.Location) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Position(org.eclipse.lsp4j.Position) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 7 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp 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 SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class ActiveProfilesProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0) {
        StringBuilder markdown = new StringBuilder();
        markdown.append("**Active Profiles**\n\n");
        boolean hasInterestingApp = false;
        for (SpringBootApp app : runningApps) {
            List<String> profiles = app.getActiveProfiles();
            if (profiles == null) {
                markdown.append(niceAppName(app) + " : _Unknown_\n\n");
            } else {
                hasInterestingApp = true;
                if (profiles.isEmpty()) {
                    markdown.append(niceAppName(app) + " : _None_\n\n");
                } else {
                    markdown.append(niceAppName(app) + " :\n");
                    for (String profile : profiles) {
                        markdown.append("- " + profile + "\n");
                    }
                    markdown.append("\n");
                }
            }
        }
        if (hasInterestingApp) {
            return new Hover(ImmutableList.of(Either.forLeft(markdown.toString())));
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover)

Example 9 with SpringBootApp

use of org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp in project sts4 by spring-projects.

the class LiveHoverUtils method findRelevantBeans.

public static Stream<LiveBean> findRelevantBeans(SpringBootApp app, LiveBean definedBean) {
    LiveBeansModel beansModel = app.getBeans();
    if (beansModel != null) {
        Stream<LiveBean> relevantBeans = beansModel.getBeansOfName(definedBean.getId()).stream();
        String type = definedBean.getType();
        if (type != null) {
            relevantBeans = relevantBeans.filter(bean -> type.equals(bean.getType(true)));
        }
        return relevantBeans;
    }
    return Stream.empty();
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Renderables(org.springframework.ide.vscode.commons.util.Renderables) BootJavaLanguageServerComponents(org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Stream(java.util.stream.Stream) SpringResource(org.springframework.ide.vscode.boot.java.utils.SpringResource) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean) SourceLinks(org.springframework.ide.vscode.boot.java.links.SourceLinks) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Optional(java.util.Optional) SourceLinkFactory(org.springframework.ide.vscode.boot.java.links.SourceLinkFactory) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Aggregations

SpringBootApp (org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp)9 Hover (org.eclipse.lsp4j.Hover)6 Range (org.eclipse.lsp4j.Range)4 LiveBean (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)4 LiveBeansModel (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel)4 Stream (java.util.stream.Stream)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)2 Log (org.springframework.ide.vscode.commons.util.Log)2 Renderables (org.springframework.ide.vscode.commons.util.Renderables)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 Annotation (org.eclipse.jdt.core.dom.Annotation)1 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1