Search in sources :

Example 51 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-core by eclipse.

the class CommandServiceTest method testExecute.

@Test
public void testExecute() {
    final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
        ClientCapabilities _clientCapabilities = new ClientCapabilities();
        final Procedure1<ClientCapabilities> _function_1 = (ClientCapabilities it_1) -> {
            WorkspaceClientCapabilities _workspaceClientCapabilities = new WorkspaceClientCapabilities();
            final Procedure1<WorkspaceClientCapabilities> _function_2 = (WorkspaceClientCapabilities it_2) -> {
                ExecuteCommandCapabilities _executeCommandCapabilities = new ExecuteCommandCapabilities();
                final Procedure1<ExecuteCommandCapabilities> _function_3 = (ExecuteCommandCapabilities it_3) -> {
                    it_3.setDynamicRegistration(Boolean.valueOf(true));
                };
                ExecuteCommandCapabilities _doubleArrow = ObjectExtensions.<ExecuteCommandCapabilities>operator_doubleArrow(_executeCommandCapabilities, _function_3);
                it_2.setExecuteCommand(_doubleArrow);
            };
            WorkspaceClientCapabilities _doubleArrow = ObjectExtensions.<WorkspaceClientCapabilities>operator_doubleArrow(_workspaceClientCapabilities, _function_2);
            it_1.setWorkspace(_doubleArrow);
        };
        ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function_1);
        it.setCapabilities(_doubleArrow);
    };
    this.initialize(_function);
    final Procedure1<CommandServiceTest.TestExecuteCommandConfiguration> _function_1 = (CommandServiceTest.TestExecuteCommandConfiguration it) -> {
        it.command = "testlang.a";
        final Consumer<Object> _function_2 = (Object it_1) -> {
            if ((it_1 instanceof String)) {
                this.assertEquals("a", ((String) it_1));
            } else {
                Assert.fail("no string");
            }
        };
        it.assertCommandResult = _function_2;
    };
    this.testExecuteCommand(_function_1);
    final Procedure1<CommandServiceTest.TestExecuteCommandConfiguration> _function_2 = (CommandServiceTest.TestExecuteCommandConfiguration it) -> {
        it.command = "testlang.b";
        final Consumer<Object> _function_3 = (Object it_1) -> {
            if ((it_1 instanceof String)) {
                this.assertEquals("b", ((String) it_1));
            } else {
                Assert.fail("no string");
            }
        };
        it.assertCommandResult = _function_3;
    };
    this.testExecuteCommand(_function_2);
    final Procedure1<CommandServiceTest.TestExecuteCommandConfiguration> _function_3 = (CommandServiceTest.TestExecuteCommandConfiguration it) -> {
        it.command = "doesnotexist.c";
        final Consumer<Object> _function_4 = (Object it_1) -> {
            Assert.assertNull(it_1);
        };
        it.assertCommandResult = _function_4;
    };
    this.testExecuteCommand(_function_3);
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) InitializeParams(org.eclipse.lsp4j.InitializeParams) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) Consumer(java.util.function.Consumer) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 52 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-core by eclipse.

the class ServerTest method testMissingInitialize.

@Test
public void testMissingInitialize() {
    try {
        try {
            TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
            final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
                TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier();
                final Procedure1<TextDocumentIdentifier> _function_1 = (TextDocumentIdentifier it_1) -> {
                    it_1.setUri("file:/home/test/workspace/mydoc.testlang");
                };
                TextDocumentIdentifier _doubleArrow = ObjectExtensions.<TextDocumentIdentifier>operator_doubleArrow(_textDocumentIdentifier, _function_1);
                it.setTextDocument(_doubleArrow);
            };
            TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
            this.languageServer.definition(_doubleArrow).get();
            Assert.fail("Expected a ResponseErrorException");
        } catch (final Throwable _t) {
            if (_t instanceof ExecutionException) {
                final ExecutionException exception = (ExecutionException) _t;
                Throwable _cause = exception.getCause();
                Assert.assertEquals(ResponseErrorCode.serverNotInitialized.getValue(), ((ResponseErrorException) _cause).getResponseError().getCode());
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 53 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-core by eclipse.

the class UnknownProjectConfigTest method testCompletionWithInmemoryScheme_01.

@Test
public void testCompletionWithInmemoryScheme_01() {
    final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
        it.setRootUri(null);
    };
    this.initialize(_function);
    final String inmemoryUri = "inmemory:/mydoc.testlang";
    DidOpenTextDocumentParams _didOpenTextDocumentParams = new DidOpenTextDocumentParams();
    final Procedure1<DidOpenTextDocumentParams> _function_1 = (DidOpenTextDocumentParams it) -> {
        TextDocumentItem _textDocumentItem = new TextDocumentItem();
        final Procedure1<TextDocumentItem> _function_2 = (TextDocumentItem it_1) -> {
            it_1.setUri(inmemoryUri);
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("type Foo {}");
            _builder.newLine();
            it_1.setText(_builder.toString());
        };
        TextDocumentItem _doubleArrow = ObjectExtensions.<TextDocumentItem>operator_doubleArrow(_textDocumentItem, _function_2);
        it.setTextDocument(_doubleArrow);
    };
    DidOpenTextDocumentParams _doubleArrow = ObjectExtensions.<DidOpenTextDocumentParams>operator_doubleArrow(_didOpenTextDocumentParams, _function_1);
    this.languageServer.didOpen(_doubleArrow);
    this.checkCompletion(inmemoryUri);
}
Also used : TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) InitializeParams(org.eclipse.lsp4j.InitializeParams) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 54 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-core by eclipse.

the class CodeActionService method recordWorkspaceEdit.

private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
    try {
        final XtextResourceSet rs = new XtextResourceSet();
        final Resource copy = rs.createResource(resource.getURI());
        String _text = resource.getParseResult().getRootNode().getText();
        StringInputStream _stringInputStream = new StringInputStream(_text);
        copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
        this.serializer.<Resource>addModification(copy, mod);
        final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
        this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
        WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
        final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
            Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
            for (final ITextDocumentChange documentchange : _filter) {
                {
                    final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
                        TextEdit _textEdit = new TextEdit();
                        final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
                            it_1.setNewText(replacement.getReplacementText());
                            Position _position = doc.getPosition(replacement.getOffset());
                            Position _position_1 = doc.getPosition(replacement.getEndOffset());
                            Range _range = new Range(_position, _position_1);
                            it_1.setRange(_range);
                        };
                        return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
                    };
                    final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
                    it.getChanges().put(documentchange.getNewURI().toString(), edits);
                }
            }
        };
        return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ITextDocumentChange(org.eclipse.xtext.ide.serializer.ITextDocumentChange) Range(org.eclipse.lsp4j.Range) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) TextEdit(org.eclipse.lsp4j.TextEdit) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange)

Example 55 with Procedure1

use of org.eclipse.xtext.xbase.lib.Procedures.Procedure1 in project xtext-core by eclipse.

the class CodeActionService method fixInvalidName.

private Command fixInvalidName(final Diagnostic d, final Document doc, final XtextResource res, final CodeActionParams params) {
    final String string = doc.getSubstring(d.getRange());
    Command _command = new Command();
    final Procedure1<Command> _function = (Command it) -> {
        it.setCommand("my.textedit.command");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("Make \'");
        _builder.append(string);
        _builder.append("\' upper case");
        it.setTitle(_builder.toString());
        WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
        final Procedure1<WorkspaceEdit> _function_1 = (WorkspaceEdit it_1) -> {
            TextEdit _textEdit = new TextEdit();
            final Procedure1<TextEdit> _function_2 = (TextEdit it_2) -> {
                it_2.setNewText(StringExtensions.toFirstUpper(string));
                it_2.setRange(d.getRange());
            };
            TextEdit _doubleArrow = ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
            it_1.getChanges().put(params.getTextDocument().getUri(), Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_doubleArrow)));
        };
        WorkspaceEdit _doubleArrow = ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function_1);
        it.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList(_doubleArrow)));
    };
    return ObjectExtensions.<Command>operator_doubleArrow(_command, _function);
}
Also used : Command(org.eclipse.lsp4j.Command) TextEdit(org.eclipse.lsp4j.TextEdit) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit)

Aggregations

Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)173 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)99 Test (org.junit.Test)98 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)28 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)20 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)20 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)20 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)18 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)16 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)16 EList (org.eclipse.emf.common.util.EList)14 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)14 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)14 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)13 EObject (org.eclipse.emf.ecore.EObject)11 Method (java.lang.reflect.Method)10 AbstractBuilderTest (org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)10 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)10 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)10 Field (java.lang.reflect.Field)9