Search in sources :

Example 1 with Hover

use of org.eclipse.lsp4j.Hover in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method mxmlHover.

private CompletableFuture<Hover> mxmlHover(TextDocumentPositionParams position, IMXMLTagData offsetTag) {
    IDefinition definition = getDefinitionForMXMLNameAtOffset(offsetTag, currentOffset);
    if (definition == null) {
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    if (isInsideTagPrefix(offsetTag, currentOffset)) {
        //inside the prefix
        String prefix = offsetTag.getPrefix();
        Hover result = new Hover();
        List<String> contents = new ArrayList<>();
        StringBuilder detailBuilder = new StringBuilder();
        detailBuilder.append(MARKDOWN_CODE_BLOCK_MXML_START);
        if (prefix.length() > 0) {
            detailBuilder.append("xmlns:" + prefix + "=\"" + offsetTag.getURI() + "\"");
        } else {
            detailBuilder.append("xmlns=\"" + offsetTag.getURI() + "\"");
        }
        detailBuilder.append(MARKDOWN_CODE_BLOCK_END);
        contents.add(detailBuilder.toString());
        result.setContents(contents);
        return CompletableFuture.completedFuture(result);
    }
    Hover result = new Hover();
    String detail = getDefinitionDetail(definition);
    List<String> contents = new ArrayList<>();
    contents.add(MARKDOWN_CODE_BLOCK_NEXTGENAS_START + detail + MARKDOWN_CODE_BLOCK_END);
    result.setContents(contents);
    return CompletableFuture.completedFuture(result);
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 2 with Hover

use of org.eclipse.lsp4j.Hover in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method hover.

/**
     * Returns information to display in a tooltip when the mouse hovers over
     * something in a text document.
     */
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
    String textDocumentUri = position.getTextDocument().getUri();
    if (!textDocumentUri.endsWith(AS_EXTENSION) && !textDocumentUri.endsWith(MXML_EXTENSION)) {
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    IMXMLTagData offsetTag = getOffsetMXMLTag(position);
    if (offsetTag != null) {
        IASNode embeddedNode = getEmbeddedActionScriptNodeInMXMLTag(offsetTag, currentOffset, position);
        if (embeddedNode != null) {
            return actionScriptHoverWithNode(position, embeddedNode);
        }
        //so that's why we call isMXMLTagValidForCompletion()
        if (isMXMLTagValidForCompletion(offsetTag)) {
            return mxmlHover(position, offsetTag);
        }
    }
    return actionScriptHover(position);
}
Also used : IASNode(org.apache.flex.compiler.tree.as.IASNode) Hover(org.eclipse.lsp4j.Hover) IMXMLTagData(org.apache.flex.compiler.mxml.IMXMLTagData)

Example 3 with Hover

use of org.eclipse.lsp4j.Hover in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method actionScriptHoverWithNode.

private CompletableFuture<Hover> actionScriptHoverWithNode(TextDocumentPositionParams position, IASNode offsetNode) {
    IDefinition definition = null;
    if (offsetNode == null) {
        //we couldn't find a node at the specified location
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    //any hover information for it.
    if (definition == null && offsetNode instanceof IIdentifierNode && !(offsetNode instanceof INamespaceDecorationNode)) {
        IIdentifierNode identifierNode = (IIdentifierNode) offsetNode;
        definition = identifierNode.resolve(currentUnit.getProject());
    }
    if (definition == null) {
        return CompletableFuture.completedFuture(new Hover(Collections.emptyList(), null));
    }
    Hover result = new Hover();
    String detail = getDefinitionDetail(definition);
    List<String> contents = new ArrayList<>();
    contents.add(MARKDOWN_CODE_BLOCK_NEXTGENAS_START + detail + MARKDOWN_CODE_BLOCK_END);
    result.setContents(contents);
    return CompletableFuture.completedFuture(result);
}
Also used : INamespaceDecorationNode(org.apache.flex.compiler.tree.as.INamespaceDecorationNode) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) IIdentifierNode(org.apache.flex.compiler.tree.as.IIdentifierNode) IDefinition(org.apache.flex.compiler.definitions.IDefinition)

Example 4 with Hover

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

the class HoverHandler method hover.

public Hover hover(TextDocumentPositionParams position, IProgressMonitor monitor) {
    ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri());
    List<Either<String, MarkedString>> content = null;
    if (unit != null && !monitor.isCanceled()) {
        content = computeHover(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor);
    }
    Hover $ = new Hover();
    $.setContents(content);
    return $;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) Either(org.eclipse.lsp4j.jsonrpc.messages.Either)

Example 5 with Hover

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

the class HoverHandlerTest method testHoverUnresolvedType.

@Test
public void testHoverUnresolvedType() throws Exception {
    importProjects("eclipse/unresolvedtype");
    project = WorkspaceHelper.getProject("unresolvedtype");
    handler = new HoverHandler(preferenceManager);
    // given
    // Hovers on the IFoo
    String payload = createHoverRequest("src/pckg/Foo.java", 2, 31);
    TextDocumentPositionParams position = getParams(payload);
    // when
    Hover hover = handler.hover(position, monitor);
    assertNotNull(hover);
    assertTrue("Unexpected hover ", hover.getContents().isEmpty());
}
Also used : Hover(org.eclipse.lsp4j.Hover) MarkedString(org.eclipse.lsp4j.MarkedString) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

Hover (org.eclipse.lsp4j.Hover)42 MarkedString (org.eclipse.lsp4j.MarkedString)14 Test (org.junit.Test)12 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)11 ArrayList (java.util.ArrayList)10 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)10 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)9 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