Search in sources :

Example 26 with Range

use of org.eclipse.lsp4j.Range 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 27 with Range

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

the class WebFluxCodeLensProviderTest method containsCodeLens.

private boolean containsCodeLens(List<? extends CodeLens> codeLenses, String commandTitle, int startLine, int startPosition, int endLine, int endPosition) {
    for (CodeLens codeLens : codeLenses) {
        Command command = codeLens.getCommand();
        Range range = codeLens.getRange();
        if (command.getTitle().equals(commandTitle) && range.getStart().getLine() == startLine && range.getStart().getCharacter() == startPosition && range.getEnd().getLine() == endLine && range.getEnd().getCharacter() == endPosition) {
            return true;
        }
    }
    return false;
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) Command(org.eclipse.lsp4j.Command) Range(org.eclipse.lsp4j.Range)

Example 28 with Range

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

the class WebfluxElementsInformationTest method testContainsMultipleLineRange.

@Test
public void testContainsMultipleLineRange() {
    Range range = new Range(new Position(2, 10), new Position(4, 5));
    WebfluxElementsInformation information = new WebfluxElementsInformation(new Range[] { range });
    assertFalse(information.contains(new Position(1, 1)));
    assertFalse(information.contains(new Position(1, 11)));
    assertFalse(information.contains(new Position(2, 1)));
    assertFalse(information.contains(new Position(2, 9)));
    assertTrue(information.contains(new Position(2, 10)));
    assertTrue(information.contains(new Position(2, 11)));
    assertTrue(information.contains(new Position(2, 40)));
    assertTrue(information.contains(new Position(3, 1)));
    assertTrue(information.contains(new Position(3, 12)));
    assertTrue(information.contains(new Position(3, 50)));
    assertTrue(information.contains(new Position(4, 1)));
    assertTrue(information.contains(new Position(4, 5)));
    assertFalse(information.contains(new Position(4, 6)));
    assertFalse(information.contains(new Position(4, 10)));
    assertFalse(information.contains(new Position(5, 1)));
    assertFalse(information.contains(new Position(5, 20)));
}
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 29 with Range

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

the class WebfluxElementsInformationTest method testContainsMultipleRanges.

@Test
public void testContainsMultipleRanges() {
    Range range1 = new Range(new Position(2, 10), new Position(3, 20));
    Range range2 = new Range(new Position(5, 2), new Position(5, 3));
    Range range3 = new Range(new Position(10, 10), new Position(20, 20));
    Range range4 = new Range(new Position(4, 40), new Position(6, 3));
    WebfluxElementsInformation information = new WebfluxElementsInformation(new Range[] { range1, range2, range3, range4 });
    assertFalse(information.contains(new Position(2, 9)));
    assertTrue(information.contains(new Position(2, 10)));
    assertTrue(information.contains(new Position(3, 19)));
    assertTrue(information.contains(new Position(3, 20)));
    assertFalse(information.contains(new Position(3, 21)));
    assertTrue(information.contains(new Position(5, 1)));
    assertTrue(information.contains(new Position(5, 2)));
    assertTrue(information.contains(new Position(5, 3)));
    assertTrue(information.contains(new Position(5, 4)));
    assertFalse(information.contains(new Position(4, 39)));
    assertTrue(information.contains(new Position(4, 40)));
    assertTrue(information.contains(new Position(4, 41)));
    assertTrue(information.contains(new Position(6, 2)));
    assertTrue(information.contains(new Position(6, 3)));
    assertFalse(information.contains(new Position(6, 4)));
    assertFalse(information.contains(new Position(9, 10)));
    assertFalse(information.contains(new Position(10, 9)));
    assertTrue(information.contains(new Position(10, 10)));
    assertTrue(information.contains(new Position(10, 21)));
    assertTrue(information.contains(new Position(15, 3)));
    assertTrue(information.contains(new Position(20, 20)));
    assertFalse(information.contains(new Position(20, 21)));
    assertFalse(information.contains(new Position(23, 1)));
}
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 30 with Range

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

the class WebfluxElementsInformationTest method testContainsSingleCharacterRange.

@Test
public void testContainsSingleCharacterRange() {
    Range range = new Range(new Position(3, 10), new Position(3, 10));
    WebfluxElementsInformation information = new WebfluxElementsInformation(new Range[] { range });
    assertFalse(information.contains(new Position(3, 9)));
    assertTrue(information.contains(new Position(3, 10)));
    assertFalse(information.contains(new Position(3, 11)));
}
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)

Aggregations

Range (org.eclipse.lsp4j.Range)293 Test (org.junit.Test)178 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)153 Position (org.eclipse.lsp4j.Position)111 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)105 AbstractSelectionTest (org.eclipse.jdt.ls.core.internal.correction.AbstractSelectionTest)54 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)47 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)47 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)41 ArrayList (java.util.ArrayList)39 Command (org.eclipse.lsp4j.Command)34 List (java.util.List)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)31 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)30 Diagnostic (org.eclipse.lsp4j.Diagnostic)29 TextEdit (org.eclipse.lsp4j.TextEdit)29 CodeAction (org.eclipse.lsp4j.CodeAction)28 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)27 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)25 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)21