Search in sources :

Example 1 with ColoringInformation

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();
}
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 2 with ColoringInformation

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);
}
Also used : Path(java.nio.file.Path) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ColoringInformation(org.eclipse.lsp4j.ColoringInformation) List(java.util.List) File(java.io.File) Map(java.util.Map) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Aggregations

List (java.util.List)2 ColoringInformation (org.eclipse.lsp4j.ColoringInformation)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 EObject (org.eclipse.emf.ecore.EObject)1 Position (org.eclipse.lsp4j.Position)1 Range (org.eclipse.lsp4j.Range)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)1 Operation (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation)1 Property (org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Property)1 INode (org.eclipse.xtext.nodemodel.INode)1 Test (org.junit.Test)1