Search in sources :

Example 21 with Hover

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

the class ConditionalsLiveHoverProvider method provideHover.

private Hover provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
    try {
        List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
        Optional<List<LiveConditional>> val = getMatchedLiveConditionals(annotation, runningApps);
        if (val.isPresent()) {
            addHoverContent(val.get(), hoverContent);
        }
        Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength());
        Hover hover = new Hover();
        hover.setContents(hoverContent);
        hover.setRange(hoverRange);
        return hover;
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Range(org.eclipse.lsp4j.Range)

Example 22 with Hover

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

the class ConditionalsLiveHoverTest method PT152535713testMultipleLiveHoverHints.

@Test
public void PT152535713testMultipleLiveHoverHints() throws Exception {
    // Tests fix for PT152535713. Ensure that in a method with multiple
    // conditionals,
    // hovering over any one conditional annotation only shows content for that
    // conditional
    // and not any of the other ones
    File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-conditionals-live-hover/").toURI());
    String docUri = directory.toPath().resolve("src/main/java/example/MultipleConditionalsPT152535713.java").toUri().toString();
    // Build a mock running boot app
    mockAppProvider.builder().isSpringBootApp(true).port("1000").processId("70000").host("cfapps.io").processName("test-conditionals-live-hover").liveConditionalsJson("{\"positiveMatches\":{\"MultipleConditionalsPT152535713#hi\":[{\"condition\":\"OnWebApplicationCondition\",\"message\":\"@ConditionalOnWebApplication (required) found StandardServletEnvironment\"},{\"condition\":\"OnJavaCondition\",\"message\":\"@ConditionalOnJava (1.8 or newer) found 1.8\"}]}}").build();
    harness.intialize(directory);
    Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
    editor.assertHoverExactText("@ConditionalOnWebApplication", "@ConditionalOnWebApplication (required) found StandardServletEnvironment\n" + "\n" + "Process [PID=70000, name=`test-conditionals-live-hover`]");
    editor.assertHoverExactText("@ConditionalOnJava(value=ConditionalOnJava.JavaVersion.EIGHT)", "@ConditionalOnJava (1.8 or newer) found 1.8\n" + "\n" + "Process [PID=70000, name=`test-conditionals-live-hover`]");
    // Test that the hovers dont have extra information of the other conditionals:
    Hover hover = editor.getHover("@ConditionalOnWebApplication");
    String hoverContent = editor.hoverString(hover);
    assertFalse(hoverContent.contains("@ConditionalOnJava"));
    hover = editor.getHover("@ConditionalOnJava(value=ConditionalOnJava.JavaVersion.EIGHT)");
    hoverContent = editor.hoverString(hover);
    assertFalse(hoverContent.contains("@ConditionalOnWebApplication"));
}
Also used : Hover(org.eclipse.lsp4j.Hover) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) File(java.io.File) Test(org.junit.Test)

Example 23 with Hover

use of org.eclipse.lsp4j.Hover in project xtext-core by eclipse.

the class HoverService method hover.

protected Hover hover(final HoverContext context) {
    if ((context == null)) {
        return IHoverService.EMPTY_HOVER;
    }
    final List<Either<String, MarkedString>> contents = this.getContents(context);
    if ((contents == null)) {
        return IHoverService.EMPTY_HOVER;
    }
    final Range range = this.getRange(context);
    if ((range == null)) {
        return IHoverService.EMPTY_HOVER;
    }
    return new Hover(contents, range);
}
Also used : Hover(org.eclipse.lsp4j.Hover) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range)

Example 24 with Hover

use of org.eclipse.lsp4j.Hover in project xtext-core by eclipse.

the class AbstractLanguageServerTest method testHover.

protected void testHover(final Procedure1<? super HoverTestConfiguration> configurator) {
    try {
        @Extension final HoverTestConfiguration configuration = new HoverTestConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
        final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
        };
        TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
        final CompletableFuture<Hover> hoverFuture = this.languageServer.hover(_doubleArrow);
        final Hover hover = hoverFuture.get();
        Procedure1<? super Hover> _assertHover = configuration.getAssertHover();
        boolean _tripleNotEquals = (_assertHover != null);
        if (_tripleNotEquals) {
            configuration.getAssertHover().apply(hover);
        } else {
            final String actualHover = this.toExpectation(hover);
            this.assertEquals(configuration.getExpectedHover(), actualHover);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) HoverTestConfiguration(org.eclipse.xtext.testing.HoverTestConfiguration) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Example 25 with Hover

use of org.eclipse.lsp4j.Hover in project eclipse.jdt.ls by eclipse.

the class HoverHandlerTest method getTitleHover.

/**
 * @param cu
 * @return
 */
private String getTitleHover(ICompilationUnit cu, int line, int character) {
    // when
    Hover hover = getHover(cu, line, character);
    // then
    assertNotNull(hover);
    MarkedString result = hover.getContents().get(0).getRight();
    return result.getValue();
}
Also used : Hover(org.eclipse.lsp4j.Hover) MarkedString(org.eclipse.lsp4j.MarkedString)

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