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();
}
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);
}
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);
}
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);
}
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());
}
Aggregations