Search in sources :

Example 16 with Document

use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.

the class WorkspaceManagerTest method testDoRead.

@Test
public void testDoRead() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Test {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("string foo");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final URI path = this.operator_mappedTo("MyType1.testlang", _builder);
    this.workspaceManger.doBuild(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(path)), CollectionLiterals.<URI>emptyList(), null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("type Test {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("Test foo");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final String inMemContents = _builder_1.toString();
    this.workspaceManger.didOpen(path, 1, inMemContents).build(null);
    final Function2<Document, XtextResource, String> _function = (Document $0, XtextResource $1) -> {
        return $0.getContents();
    };
    Assert.assertEquals(inMemContents, this.workspaceManger.<String>doRead(path, _function));
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 17 with Document

use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.

the class DocumentTest method testOffSet_empty.

@Test
public void testOffSet_empty() {
    Document _document = new Document(1, "");
    final Procedure1<Document> _function = (Document it) -> {
        Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
        try {
            it.getOffSet(this.position(0, 12));
            Assert.fail();
        } catch (final Throwable _t) {
            if (_t instanceof IndexOutOfBoundsException) {
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
    };
    ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
Also used : Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Example 18 with Document

use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.

the class DocumentTest method testUpdate_03.

@Test
public void testUpdate_03() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("hello world");
    _builder.newLine();
    _builder.append("foo");
    _builder.newLine();
    _builder.append("bar");
    String _normalize = this.normalize(_builder);
    Document _document = new Document(1, _normalize);
    final Procedure1<Document> _function = (Document it) -> {
        TextEdit _change = this.change(this.position(0, 0), this.position(2, 3), "");
        Assert.assertEquals("", it.applyChanges(Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
    };
    ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
Also used : TextEdit(org.eclipse.lsp4j.TextEdit) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Example 19 with Document

use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.

the class DocumentTest method testUpdate_01.

@Test
public void testUpdate_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("hello world");
    _builder.newLine();
    _builder.append("foo");
    _builder.newLine();
    _builder.append("bar");
    _builder.newLine();
    String _normalize = this.normalize(_builder);
    Document _document = new Document(1, _normalize);
    final Procedure1<Document> _function = (Document it) -> {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("hello world");
        _builder_1.newLine();
        _builder_1.append("bar");
        _builder_1.newLine();
        TextEdit _change = this.change(this.position(1, 0), this.position(2, 0), "");
        Assert.assertEquals(this.normalize(_builder_1), it.applyChanges(Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
    };
    ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
Also used : TextEdit(org.eclipse.lsp4j.TextEdit) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Example 20 with Document

use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.

the class DocumentTest method testUpdate_nonIncrementalChange.

@Test
public void testUpdate_nonIncrementalChange() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("hello world");
    _builder.newLine();
    _builder.append("foo");
    _builder.newLine();
    _builder.append("bar");
    String _normalize = this.normalize(_builder);
    Document _document = new Document(1, _normalize);
    final Procedure1<Document> _function = (Document it) -> {
        TextEdit _change = this.change(null, null, " foo ");
        Assert.assertEquals(" foo ", it.applyChanges(Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
    };
    ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
Also used : TextEdit(org.eclipse.lsp4j.TextEdit) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Aggregations

Document (org.eclipse.xtext.ide.server.Document)22 URI (org.eclipse.emf.common.util.URI)11 XtextResource (org.eclipse.xtext.resource.XtextResource)10 TextEdit (org.eclipse.lsp4j.TextEdit)8 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Test (org.junit.Test)7 List (java.util.List)6 Resource (org.eclipse.emf.ecore.resource.Resource)4 CompletionList (org.eclipse.lsp4j.CompletionList)4 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)4 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 DocumentFormattingParams (org.eclipse.lsp4j.DocumentFormattingParams)2 Position (org.eclipse.lsp4j.Position)2 Range (org.eclipse.lsp4j.Range)2 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)2 ProjectManager (org.eclipse.xtext.ide.server.ProjectManager)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 FileInfo (org.eclipse.xtext.testing.FileInfo)2 RangeFormattingConfiguration (org.eclipse.xtext.testing.RangeFormattingConfiguration)2