Search in sources :

Example 36 with Hover

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

the class BootJavaHoverProvider method handle.

@Override
public Hover handle(TextDocumentPositionParams params) {
    SimpleTextDocumentService documents = server.getTextDocumentService();
    if (documents.get(params) != null) {
        TextDocument doc = documents.get(params).copy();
        try {
            int offset = doc.toOffset(params.getPosition());
            Hover hoverResult = provideHover(doc, offset);
            if (hoverResult != null) {
                return hoverResult;
            }
        } catch (Exception e) {
        }
    }
    return SimpleTextDocumentService.NO_HOVER;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) Hover(org.eclipse.lsp4j.Hover) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService)

Example 37 with Hover

use of org.eclipse.lsp4j.Hover 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 38 with Hover

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

the class Editor method assertIsHoverRegion.

public void assertIsHoverRegion(String string) throws Exception {
    int hoverPosition = getHoverPosition(string, 1);
    Hover hover = harness.getHover(doc, doc.toPosition(hoverPosition));
    assertEquals(string, getText(hover.getRange()));
}
Also used : Hover(org.eclipse.lsp4j.Hover)

Example 39 with Hover

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

the class Editor method assertTrimmedHover.

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

Example 40 with Hover

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

the class Editor method assertNoHover.

public void assertNoHover(String hoverOver) throws Exception {
    int hoverPosition = getRawText().indexOf(hoverOver) + hoverOver.length() / 2;
    Hover hover = harness.getHover(doc, doc.toPosition(hoverPosition));
    List<Either<String, MarkedString>> contents = hover.getContents();
    assertTrue(contents.toString(), contents.isEmpty());
}
Also used : Hover(org.eclipse.lsp4j.Hover) Either(org.eclipse.lsp4j.jsonrpc.messages.Either)

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