Search in sources :

Example 16 with Hover

use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.

the class Editor method assertHoverContains.

public void assertHoverContains(String hoverOver, String snippet) throws Exception {
    int hoverPosition = getHoverPosition(hoverOver, 1);
    Hover hover = harness.getHover(doc, doc.toPosition(hoverPosition));
    assertContains(snippet, hoverString(hover));
}
Also used : Hover(org.eclipse.lsp4j.Hover)

Example 17 with Hover

use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.

the class ValueHoverProvider method provideHover.

private Hover provideHover(String value, int offset, int nodeStartOffset, TextDocument doc, SpringBootApp[] runningApps) {
    try {
        LocalRange range = getPropertyRange(value, offset);
        if (range != null) {
            String propertyKey = value.substring(range.getStart(), range.getEnd());
            if (propertyKey != null) {
                Map<SpringBootApp, JSONObject> allProperties = getPropertiesFromProcesses(runningApps);
                StringBuilder hover = new StringBuilder();
                for (SpringBootApp app : allProperties.keySet()) {
                    JSONObject properties = allProperties.get(app);
                    Iterator<?> keys = properties.keys();
                    while (keys.hasNext()) {
                        String key = (String) keys.next();
                        if (properties.get(key) instanceof JSONObject) {
                            JSONObject props = properties.getJSONObject(key);
                            if (props.has(propertyKey)) {
                                String propertyValue = props.getString(propertyKey);
                                hover.append(propertyKey + " : " + propertyValue);
                                hover.append(" (from: " + key + ")\n\n");
                                hover.append(LiveHoverUtils.niceAppName(app));
                                hover.append("\n\n");
                            }
                        }
                    }
                }
                if (hover.length() > 0) {
                    Range hoverRange = doc.toRange(nodeStartOffset + range.getStart(), range.getEnd() - range.getStart());
                    Hover result = new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
                    result.setRange(hoverRange);
                    return result;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) JSONObject(org.json.JSONObject) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range)

Example 18 with Hover

use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.

the class AbstractInjectedIntoHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0) {
        LiveBean definedBean = getDefinedBean(annotation);
        if (definedBean != null) {
            StringBuilder hover = new StringBuilder();
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = false;
            for (SpringBootApp app : runningApps) {
                LiveBeansModel beans = app.getBeans();
                List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
                if (!relevantBeans.isEmpty()) {
                    if (!hasInterestingApp) {
                        hasInterestingApp = true;
                    } else {
                        hover.append("\n\n");
                    }
                    hover.append(LiveHoverUtils.niceAppName(app) + ":");
                    for (LiveBean bean : relevantBeans) {
                        addInjectedInto(definedBean, hover, beans, bean, project);
                        addAutomaticallyWiredContructor(hover, annotation, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp) {
                return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
            }
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Example 19 with Hover

use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.

the class ComponentInjectionsHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, TypeDeclaration typeDeclaration, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0 && !isComponentAnnotatedType(typeDeclaration)) {
        LiveBean definedBean = getDefinedBeanForType(typeDeclaration, null);
        if (definedBean != null) {
            StringBuilder hover = new StringBuilder();
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = false;
            for (SpringBootApp app : runningApps) {
                LiveBeansModel beans = app.getBeans();
                List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
                if (!relevantBeans.isEmpty()) {
                    if (!hasInterestingApp) {
                        hasInterestingApp = true;
                    } else {
                        hover.append("\n\n");
                    }
                    hover.append(LiveHoverUtils.niceAppName(app) + ":");
                    for (LiveBean bean : relevantBeans) {
                        addInjectedInto(definedBean, hover, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp) {
                return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
            }
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Example 20 with Hover

use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.

the class AutowiredHoverProvider 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 hover = new StringBuilder();
        LiveBean definedBean = getDefinedBean(annotation);
        if (definedBean != null) {
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = false;
            boolean hasAutowiring = false;
            for (SpringBootApp app : runningApps) {
                LiveBeansModel beans = app.getBeans();
                List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
                if (!relevantBeans.isEmpty()) {
                    if (!hasInterestingApp) {
                        hasInterestingApp = true;
                    } else {
                        hover.append("\n\n");
                    }
                    hover.append(LiveHoverUtils.niceAppName(app) + ":");
                    for (LiveBean bean : relevantBeans) {
                        hover.append("\n\n");
                        hasAutowiring |= addAutomaticallyWired(hover, annotation, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp && hasAutowiring) {
                return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
            }
        }
    }
    return null;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Aggregations

Hover (org.eclipse.lsp4j.Hover)41 MarkedString (org.eclipse.lsp4j.MarkedString)14 Test (org.junit.Test)12 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)11 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)11 ArrayList (java.util.ArrayList)10 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)10 Range (org.eclipse.lsp4j.Range)5 SpringBootApp (org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp)5 List (java.util.List)4 Position (org.eclipse.lsp4j.Position)3 LiveBean (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)3 LiveBeansModel (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel)3 File (java.io.File)2 URI (java.net.URI)2 IDefinition (org.apache.flex.compiler.definitions.IDefinition)2 PositionTreeVisitor (org.ballerinalang.langserver.common.position.PositionTreeVisitor)2 IClassFile (org.eclipse.jdt.core.IClassFile)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 SimpleTextDocumentService (org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)2