Search in sources :

Example 11 with Hover

use of org.eclipse.lsp4j.Hover in project ballerina by ballerina-lang.

the class HoverUtil method getDefaultHoverObject.

/**
 * Get the default hover object.
 *
 * @return hover default hover object.
 */
private static Hover getDefaultHoverObject() {
    Hover hover = new Hover();
    List<Either<String, MarkedString>> contents = new ArrayList<>();
    contents.add(Either.forLeft(""));
    hover.setContents(contents);
    return hover;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either)

Example 12 with Hover

use of org.eclipse.lsp4j.Hover in project ballerina by ballerina-lang.

the class HoverUtil method getHoverContent.

/**
 * get current hover content.
 *
 * @param hoverContext        text document context for the hover provider.
 * @param currentBLangPackage package which currently user working on.
 * @return return Hover object.
 */
public static Hover getHoverContent(TextDocumentServiceContext hoverContext, BLangPackage currentBLangPackage, LSPackageCache packageContext) {
    PositionTreeVisitor positionTreeVisitor = new PositionTreeVisitor(hoverContext);
    currentBLangPackage.accept(positionTreeVisitor);
    Hover hover;
    // If the cursor is on a node of the current package go inside, else check builtin and native packages.
    if (hoverContext.get(NodeContextKeys.PACKAGE_OF_NODE_KEY) != null) {
        hover = getHoverInformation(packageContext.findPackage(hoverContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY), hoverContext.get(NodeContextKeys.PACKAGE_OF_NODE_KEY)), hoverContext);
    } else {
        hover = new Hover();
        List<Either<String, MarkedString>> contents = new ArrayList<>();
        contents.add(Either.forLeft(""));
        hover.setContents(contents);
    }
    return hover;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) PositionTreeVisitor(org.ballerinalang.langserver.common.position.PositionTreeVisitor)

Example 13 with Hover

use of org.eclipse.lsp4j.Hover in project ballerina by ballerina-lang.

the class HoverUtil method getDocumentationContent.

/**
 * Get documentation content.
 *
 * @param docAnnotation list of doc annotation
 * @return {@link Hover} hover object.
 */
private static Hover getDocumentationContent(List<BLangDocumentation> docAnnotation) {
    Hover hover = new Hover();
    StringBuilder content = new StringBuilder();
    BLangDocumentation bLangDocumentation = docAnnotation.get(0);
    Map<String, List<BLangDocumentationAttribute>> filterAttributes = filterDocumentationAttributes(docAnnotation.get(0));
    if (!bLangDocumentation.documentationText.isEmpty()) {
        content.append(getFormattedHoverDocContent(ContextConstants.DESCRIPTION, bLangDocumentation.documentationText));
    }
    if (filterAttributes.get(ContextConstants.DOC_RECEIVER) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_RECEIVER, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RECEIVER))));
    }
    if (filterAttributes.get(ContextConstants.DOC_PARAM) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_PARAM, getDocAttributes(filterAttributes.get(ContextConstants.DOC_PARAM))));
    }
    if (filterAttributes.get(ContextConstants.DOC_FIELD) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_FIELD, getDocAttributes(filterAttributes.get(ContextConstants.DOC_FIELD))));
    }
    if (filterAttributes.get(ContextConstants.DOC_RETURN) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_RETURN, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RETURN))));
    }
    if (filterAttributes.get(ContextConstants.DOC_VARIABLE) != null) {
        content.append(getFormattedHoverDocContent(ContextConstants.DOC_VARIABLE, getDocAttributes(filterAttributes.get(ContextConstants.DOC_VARIABLE))));
    }
    List<Either<String, MarkedString>> contents = new ArrayList<>();
    contents.add(Either.forLeft(content.toString()));
    hover.setContents(contents);
    return hover;
}
Also used : Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) ArrayList(java.util.ArrayList) List(java.util.List) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 14 with Hover

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

the class Editor method assertHoverExactText.

/**
 * Verifies an expected text is the hover text that is computed when
 * hovering mouse at position at the end of first occurrence of a given
 * string in the editor.
 */
public void assertHoverExactText(String afterString, String expectedHover) throws Exception {
    int pos = getRawText().indexOf(afterString);
    if (pos >= 0) {
        pos += afterString.length();
    }
    Hover hover = harness.getHover(doc, doc.toPosition(pos));
    assertEquals(expectedHover, hoverString(hover));
}
Also used : Hover(org.eclipse.lsp4j.Hover)

Example 15 with Hover

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

the class Editor method assertHoverContains.

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

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