Search in sources :

Example 21 with Document

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

the class DocumentTest method testOffSet.

@Test
public void testOffSet() {
    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) -> {
        Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
        Assert.assertEquals(11, it.getOffSet(this.position(0, 11)));
        try {
            it.getOffSet(this.position(0, 12));
            Assert.fail();
        } catch (final Throwable _t) {
            if (_t instanceof IndexOutOfBoundsException) {
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
        Assert.assertEquals(12, it.getOffSet(this.position(1, 0)));
        Assert.assertEquals(13, it.getOffSet(this.position(1, 1)));
        Assert.assertEquals(14, it.getOffSet(this.position(1, 2)));
        Assert.assertEquals(16, it.getOffSet(this.position(2, 0)));
        Assert.assertEquals(19, it.getOffSet(this.position(2, 3)));
    };
    ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

Example 22 with Document

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

the class FormattingTest method doTestAPIMaintenanceLayer.

private void doTestAPIMaintenanceLayer(final FormattingService fs) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type Foo{int bar} type Bar{Foo foo}");
        final String model = _builder.toString();
        final XtextResourceSet rs = this.rsp.get();
        Resource _createResource = rs.createResource(URI.createURI("dummy.testlang"));
        final XtextResource r = ((XtextResource) _createResource);
        StringInputStream _stringInputStream = new StringInputStream(model);
        r.load(_stringInputStream, null);
        try {
            Document _document = new Document(1, model);
            DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
            fs.format(_document, r, _documentFormattingParams, CancelIndicator.NullImpl);
            Assert.fail("IllegalStateException expected");
        } catch (final Throwable _t) {
            if (_t instanceof IllegalStateException) {
                final IllegalStateException e = (IllegalStateException) _t;
                String _message = e.getMessage();
                boolean _notEquals = (!Objects.equal(_message, "api maintenance layer broken"));
                if (_notEquals) {
                    throw e;
                }
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Document(org.eclipse.xtext.ide.server.Document)

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