Search in sources :

Example 11 with MarkedString

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

the class BallerinaTextDocumentService method hover.

@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
    return CompletableFuture.supplyAsync(() -> {
        TextDocumentServiceContext hoverContext = new TextDocumentServiceContext();
        hoverContext.put(DocumentServiceKeys.FILE_URI_KEY, position.getTextDocument().getUri());
        hoverContext.put(DocumentServiceKeys.POSITION_KEY, position);
        Hover hover;
        try {
            BLangPackage currentBLangPackage = TextDocumentServiceUtil.getBLangPackage(hoverContext, documentManager, false, LSCustomErrorStrategy.class, false).get(0);
            hoverContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, currentBLangPackage.symbol.getName().getValue());
            lSPackageCache.addPackage(currentBLangPackage);
            hover = HoverUtil.getHoverContent(hoverContext, currentBLangPackage, lSPackageCache);
        } catch (Exception | AssertionError e) {
            hover = new Hover();
            List<Either<String, MarkedString>> contents = new ArrayList<>();
            contents.add(Either.forLeft(""));
            hover.setContents(contents);
        }
        return hover;
    });
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) Hover(org.eclipse.lsp4j.Hover) MarkedString(org.eclipse.lsp4j.MarkedString) List(java.util.List) ArrayList(java.util.ArrayList) CompletionList(org.eclipse.lsp4j.CompletionList) MarkedString(org.eclipse.lsp4j.MarkedString) LSCustomErrorStrategy(org.ballerinalang.langserver.common.LSCustomErrorStrategy)

Example 12 with MarkedString

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

the class RequestMappingHoverProvider method addHoverContent.

private void addHoverContent(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods, List<Either<String, MarkedString>> hoverContent) throws Exception {
    for (int i = 0; i < mappingMethods.size(); i++) {
        Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i);
        SpringBootApp app = mappingMethod.getT2();
        String port = mappingMethod.getT2().getPort();
        String host = mappingMethod.getT2().getHost();
        List<Renderable> renderableUrls = Arrays.stream(mappingMethod.getT1().getSplitPath()).flatMap(path -> {
            String url = UrlUtil.createUrl(host, port, path);
            StringBuilder builder = new StringBuilder();
            builder.append("[");
            builder.append(url);
            builder.append("]");
            builder.append("(");
            builder.append(url);
            builder.append(")");
            return Stream.of(Renderables.text(builder.toString()), Renderables.lineBreak());
        }).collect(Collectors.toList());
        // Remove the last line break
        renderableUrls.remove(renderableUrls.size() - 1);
        hoverContent.add(Either.forLeft(Renderables.concat(renderableUrls).toMarkdown()));
        hoverContent.add(Either.forLeft(LiveHoverUtils.niceAppName(app)));
        if (i < mappingMethods.size() - 1) {
            // Three dashes == line separator in Markdown
            hoverContent.add(Either.forLeft("---"));
        }
    }
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Arrays(java.util.Arrays) IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) Range(org.eclipse.lsp4j.Range) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) HoverProvider(org.springframework.ide.vscode.boot.java.handlers.HoverProvider) Annotation(org.eclipse.jdt.core.dom.Annotation) ImmutableList(com.google.common.collect.ImmutableList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Log(org.springframework.ide.vscode.commons.util.Log) LiveHoverUtils(org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils) Collection(java.util.Collection) MarkedString(org.eclipse.lsp4j.MarkedString) Renderables(org.springframework.ide.vscode.commons.util.Renderables) Collectors(java.util.stream.Collectors) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) List(java.util.List) Stream(java.util.stream.Stream) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MarkedString(org.eclipse.lsp4j.MarkedString) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping)

Aggregations

MarkedString (org.eclipse.lsp4j.MarkedString)12 Hover (org.eclipse.lsp4j.Hover)9 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)4 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)4 Test (org.junit.Test)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1