use of org.eclipse.lsp4j.ColoringInformation 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.ColoringInformation in project xtext-core by eclipse.
the class ColoringTest method checkColoring.
@Test
public void checkColoring() {
this.initialize();
Path _path = this.root.toPath();
StringConcatenation _builder = new StringConcatenation();
_builder.append("MyModel.");
_builder.append(this.fileExtension);
final File file = _path.resolve(_builder.toString()).toFile();
final String uri = file.toURI().toString();
this.open(uri, ColoringTest.MODEL);
final Function1<Map.Entry<String, List<? extends ColoringInformation>>, String> _function = (Map.Entry<String, List<? extends ColoringInformation>> it) -> {
String _key = it.getKey();
int _lastIndexOf = it.getKey().lastIndexOf("/");
int _plus = (_lastIndexOf + 1);
return _key.substring(_plus);
};
final Function1<Map.Entry<String, List<? extends ColoringInformation>>, List<? extends ColoringInformation>> _function_1 = (Map.Entry<String, List<? extends ColoringInformation>> it) -> {
return it.getValue();
};
final String expectation = this.toExpectation(IterableExtensions.<Map.Entry<String, List<? extends ColoringInformation>>, String, List<? extends ColoringInformation>>toMap(this.getColoringParams().entrySet(), _function, _function_1));
StringConcatenation _builder_1 = new StringConcatenation();
String _name = file.getName();
_builder_1.append(_name);
_builder_1.append(" ->");
_builder_1.newLineIfNotEmpty();
_builder_1.append(" ");
_builder_1.append("* [[1, 5] .. [1, 6]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[2, 4] .. [2, 7]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[3, 4] .. [3, 7]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[6, 5] .. [6, 6]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[7, 4] .. [7, 7]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[10, 5] .. [10, 6]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[11, 4] .. [11, 7]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[14, 9] .. [14, 10]] -> [1]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("* [[15, 4] .. [15, 8]] -> [1]");
this.assertEquals(_builder_1.toString(), expectation);
}
Aggregations