Search in sources :

Example 76 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class ColoringServiceImpl method getColoring.

@Override
public List<? extends ColoringInformation> getColoring(final XtextResource resource, final Document document) {
    if ((resource == null)) {
        return CollectionLiterals.<ColoringInformation>emptyList();
    }
    final ImmutableList.Builder<ColoringInformation> builder = ImmutableList.<ColoringInformation>builder();
    final Procedure1<Object> _function = (Object it) -> {
        List<INode> _xifexpression = null;
        if ((it instanceof Property)) {
            _xifexpression = NodeModelUtils.findNodesForFeature(((EObject) it), TestLanguagePackage.Literals.MEMBER__NAME);
        } else {
            List<INode> _xifexpression_1 = null;
            if ((it instanceof Operation)) {
                _xifexpression_1 = NodeModelUtils.findNodesForFeature(((EObject) it), TestLanguagePackage.Literals.MEMBER__NAME);
            } else {
                _xifexpression_1 = CollectionLiterals.<INode>emptyList();
            }
            _xifexpression = _xifexpression_1;
        }
        final List<INode> nodes = _xifexpression;
        final Consumer<INode> _function_1 = (INode it_1) -> {
            final int start = it_1.getOffset();
            int _offset = it_1.getOffset();
            int _length = it_1.getLength();
            final int end = (_offset + _length);
            Position _position = document.getPosition(start);
            Position _position_1 = document.getPosition(end);
            final Range range = new Range(_position, _position_1);
            ColoringInformation _coloringInformation = new ColoringInformation(range, ColoringServiceImpl.STYLE_IDS);
            builder.add(_coloringInformation);
        };
        nodes.forEach(_function_1);
    };
    IteratorExtensions.<Object>forEach(EcoreUtil.<Object>getAllContents(resource, true), _function);
    return builder.build();
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Position(org.eclipse.lsp4j.Position) ImmutableList(com.google.common.collect.ImmutableList) Operation(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation) Range(org.eclipse.lsp4j.Range) Consumer(java.util.function.Consumer) EObject(org.eclipse.emf.ecore.EObject) ColoringInformation(org.eclipse.lsp4j.ColoringInformation) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Property(org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Property)

Example 77 with Range

use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.

the class DocumentHighlightComparatorTest method newRange.

private Range newRange(final int startLine, final int startChar, final int endLine, final int endChar) {
    Position _position = new Position(startLine, startChar);
    Position _position_1 = new Position(endLine, endChar);
    return new Range(_position, _position_1);
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Example 78 with Range

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

the class DocumentLifeCycleHandlerTest method changeDocumentIncrementally.

private void changeDocumentIncrementally(ICompilationUnit cu, String content, int version, int offset, int length) throws JavaModelException {
    Range range = JDTUtils.toRange(cu, offset, length);
    changeDocument(cu, content, version, range, length);
}
Also used : Range(org.eclipse.lsp4j.Range) Lsp4jAssertions.assertRange(org.eclipse.jdt.ls.core.internal.Lsp4jAssertions.assertRange)

Example 79 with Range

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

the class FormatterHandlerTest method testRangeFormatting.

@Test
public void testRangeFormatting() throws Exception {
    ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
    "package org.sample;\n" + "      public class Baz {\n" + "\tvoid foo(){\n" + "    }\n" + "	}\n");
    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    // range around foo()
    Range range = new Range(new Position(2, 0), new Position(3, 5));
    DocumentRangeFormattingParams params = new DocumentRangeFormattingParams(range);
    params.setTextDocument(textDocument);
    // ident == 3 spaces
    params.setOptions(new FormattingOptions(3, true));
    List<? extends TextEdit> edits = server.rangeFormatting(params).get();
    // @formatter:off
    String expectedText = "package org.sample;\n" + "      public class Baz {\n" + "   void foo() {\n" + "   }\n" + "	}\n";
    // @formatter:on
    String newText = TextEditUtil.apply(unit, edits);
    assertEquals(expectedText, newText);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FormattingOptions(org.eclipse.lsp4j.FormattingOptions) Position(org.eclipse.lsp4j.Position) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Example 80 with Range

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

the class CodeActionHandlerTest method testCodeAction_removeUnusedImport.

@Test
public void testCodeAction_removeUnusedImport() throws Exception {
    ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "import java.sql.*; \n" + "public class Foo {\n" + "	void foo() {\n" + "	}\n" + "}\n");
    CodeActionParams params = new CodeActionParams();
    params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
    final Range range = getRange(unit, "java.sql");
    params.setRange(range);
    params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnusedImport), range))));
    List<? extends Command> commands = server.codeAction(params).join();
    Assert.assertNotNull(commands);
    Assert.assertEquals(2, commands.size());
    Command c = commands.get(0);
    Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

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