Search in sources :

Example 96 with Range

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

the class WebfluxElementsInformationTest method testContainsSingleLineRange.

@Test
public void testContainsSingleLineRange() {
    Range range = new Range(new Position(3, 10), new Position(3, 20));
    WebfluxElementsInformation information = new WebfluxElementsInformation(new Range[] { range });
    assertFalse(information.contains(new Position(3, 5)));
    assertTrue(information.contains(new Position(3, 11)));
    assertFalse(information.contains(new Position(3, 25)));
    assertFalse(information.contains(new Position(1, 12)));
    assertFalse(information.contains(new Position(2, 1)));
    assertFalse(information.contains(new Position(4, 21)));
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) WebfluxElementsInformation(org.springframework.ide.vscode.boot.java.requestmapping.WebfluxElementsInformation) Test(org.junit.Test)

Example 97 with Range

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

the class LiveAppURLSymbolProvider method getSymbols.

public List<? extends SymbolInformation> getSymbols(String query) {
    System.out.println(query);
    List<SymbolInformation> result = new ArrayList<>();
    try {
        SpringBootApp[] runningApps = runningAppProvider.getAllRunningSpringApps().toArray(new SpringBootApp[0]);
        for (SpringBootApp app : runningApps) {
            try {
                String host = app.getHost();
                String port = app.getPort();
                Stream<String> urls = app.getRequestMappings().stream().flatMap(rm -> Arrays.stream(rm.getSplitPath())).map(path -> UrlUtil.createUrl(host, port, path));
                urls.forEach(url -> result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))));
            } catch (Exception e) {
                Log.log(e);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return result;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) RunningAppProvider(org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) Log(org.springframework.ide.vscode.commons.util.Log) SymbolKind(org.eclipse.lsp4j.SymbolKind) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Location(org.eclipse.lsp4j.Location) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) ArrayList(java.util.ArrayList) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Position(org.eclipse.lsp4j.Position) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Location(org.eclipse.lsp4j.Location)

Example 98 with Range

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

the class RequestMappingHoverProvider method provideHover.

private Hover provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
    try {
        List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
        List<Tuple2<RequestMapping, SpringBootApp>> val = getRequestMappingMethodFromRunningApp(annotation, runningApps);
        if (!val.isEmpty()) {
            addHoverContent(val, 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 : Tuple2(reactor.util.function.Tuple2) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 99 with Range

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

the class WebfluxAcceptTypeFinder method visit.

@Override
public boolean visit(MethodInvocation node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    try {
        if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
            String name = methodBinding.getName();
            if (name != null && WebfluxUtils.REQUEST_PREDICATE_ACCEPT_TYPE_METHOD.equals(name)) {
                SimpleName nameArgument = WebfluxUtils.extractSimpleNameArgument(node);
                if (nameArgument != null && nameArgument.getFullyQualifiedName() != null) {
                    Range range = doc.toRange(nameArgument.getStartPosition(), nameArgument.getLength());
                    acceptTypes.add(new WebfluxRouteElement(nameArgument.getFullyQualifiedName().toString(), range));
                }
            }
        }
    } catch (BadLocationException e) {
    // ignore
    }
    return !WebfluxUtils.isRouteMethodInvocation(methodBinding);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Range(org.eclipse.lsp4j.Range) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 100 with Range

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

the class WebfluxMethodFinder method visit.

@Override
public boolean visit(MethodInvocation node) {
    boolean visitChildren = true;
    if (node != this.root) {
        IMethodBinding methodBinding = node.resolveMethodBinding();
        try {
            if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
                String name = methodBinding.getName();
                if (name != null && WebfluxUtils.REQUEST_PREDICATE_HTTPMETHOD_METHODS.contains(name)) {
                    Range range = doc.toRange(node.getStartPosition(), node.getLength());
                    methods.add(new WebfluxRouteElement(name, range));
                } else if (name != null && WebfluxUtils.REQUEST_PREDICATE_METHOD_METHOD.equals(name)) {
                    QualifiedName qualifiedName = WebfluxUtils.extractQualifiedNameArgument(node);
                    if (qualifiedName.getName() != null) {
                        Range range = doc.toRange(qualifiedName.getStartPosition(), qualifiedName.getLength());
                        methods.add(new WebfluxRouteElement(qualifiedName.getName().toString(), range));
                    }
                }
            }
        } catch (BadLocationException e) {
        // ignore
        }
        if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
            visitChildren = false;
        }
    }
    return visitChildren;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Range(org.eclipse.lsp4j.Range) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Aggregations

Range (org.eclipse.lsp4j.Range)126 Position (org.eclipse.lsp4j.Position)59 Test (org.junit.Test)38 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)23 TextEdit (org.eclipse.lsp4j.TextEdit)23 ArrayList (java.util.ArrayList)22 List (java.util.List)17 Location (org.eclipse.lsp4j.Location)16 Document (org.eclipse.xtext.ide.server.Document)16 Diagnostic (org.eclipse.lsp4j.Diagnostic)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)13 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)13 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)12 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)12 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)9 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)9 Command (org.eclipse.lsp4j.Command)9 CompletionList (org.eclipse.lsp4j.CompletionList)9 RenameParams (org.eclipse.lsp4j.RenameParams)9 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)8