Search in sources :

Example 1 with IDisposable

use of org.eclipse.xtext.util.IDisposable in project xtext-core by eclipse.

the class CommandRegistryTest method testRegistration.

@Test
public void testRegistration() {
    final ExecutableCommandRegistry reg = new ExecutableCommandRegistry();
    ClientCapabilities _clientCapabilities = new ClientCapabilities();
    final Procedure1<ClientCapabilities> _function = (ClientCapabilities it) -> {
        WorkspaceClientCapabilities _workspaceClientCapabilities = new WorkspaceClientCapabilities();
        final Procedure1<WorkspaceClientCapabilities> _function_1 = (WorkspaceClientCapabilities it_1) -> {
            ExecuteCommandCapabilities _executeCommandCapabilities = new ExecuteCommandCapabilities();
            final Procedure1<ExecuteCommandCapabilities> _function_2 = (ExecuteCommandCapabilities it_2) -> {
                it_2.setDynamicRegistration(Boolean.valueOf(true));
            };
            ExecuteCommandCapabilities _doubleArrow = ObjectExtensions.<ExecuteCommandCapabilities>operator_doubleArrow(_executeCommandCapabilities, _function_2);
            it_1.setExecuteCommand(_doubleArrow);
        };
        WorkspaceClientCapabilities _doubleArrow = ObjectExtensions.<WorkspaceClientCapabilities>operator_doubleArrow(_workspaceClientCapabilities, _function_1);
        it.setWorkspace(_doubleArrow);
    };
    final ClientCapabilities cap = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function);
    reg.initialize(Collections.<IResourceServiceProvider>unmodifiableList(CollectionLiterals.<IResourceServiceProvider>newArrayList(this)), cap, this);
    Assert.assertEquals("static-command", IterableExtensions.<String>head(reg.getCommands()));
    ExecuteCommandParams _executeCommandParams = new ExecuteCommandParams();
    final Procedure1<ExecuteCommandParams> _function_1 = (ExecuteCommandParams it) -> {
        it.setCommand("static-command");
    };
    ExecuteCommandParams _doubleArrow = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams, _function_1);
    reg.executeCommand(_doubleArrow, null, null);
    ExecuteCommandParams _executeCommandParams_1 = new ExecuteCommandParams();
    final Procedure1<ExecuteCommandParams> _function_2 = (ExecuteCommandParams it) -> {
        it.setCommand("dynamic-command");
    };
    ExecuteCommandParams _doubleArrow_1 = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams_1, _function_2);
    reg.executeCommand(_doubleArrow_1, null, null);
    Assert.assertEquals(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("static-command")), this.commandsExecuted);
    this.commandsExecuted.clear();
    final IDisposable disposable = this.register.apply("dynamic-command");
    ExecuteCommandParams _executeCommandParams_2 = new ExecuteCommandParams();
    final Procedure1<ExecuteCommandParams> _function_3 = (ExecuteCommandParams it) -> {
        it.setCommand("dynamic-command");
    };
    ExecuteCommandParams _doubleArrow_2 = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams_2, _function_3);
    reg.executeCommand(_doubleArrow_2, null, null);
    Assert.assertEquals(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("dynamic-command")), this.commandsExecuted);
    this.commandsExecuted.clear();
    disposable.dispose();
    ExecuteCommandParams _executeCommandParams_3 = new ExecuteCommandParams();
    final Procedure1<ExecuteCommandParams> _function_4 = (ExecuteCommandParams it) -> {
        it.setCommand("dynamic-command");
    };
    ExecuteCommandParams _doubleArrow_3 = ObjectExtensions.<ExecuteCommandParams>operator_doubleArrow(_executeCommandParams_3, _function_4);
    reg.executeCommand(_doubleArrow_3, null, null);
    Assert.assertEquals(Collections.<Object>unmodifiableSet(CollectionLiterals.<Object>newHashSet()), this.commandsExecuted);
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) ExecutableCommandRegistry(org.eclipse.xtext.ide.server.commands.ExecutableCommandRegistry) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) IDisposable(org.eclipse.xtext.util.IDisposable) Test(org.junit.Test)

Example 2 with IDisposable

use of org.eclipse.xtext.util.IDisposable in project xtext-core by eclipse.

the class ExecutableCommandRegistry method register.

protected IDisposable register(final String command, final IExecutableCommandService service) {
    final String requestId = UUID.randomUUID().toString();
    Registration _registration = new Registration();
    final Procedure1<Registration> _function = (Registration it) -> {
        it.setId(requestId);
        it.setMethod(ExecutableCommandRegistry.METHOD);
        ExecuteCommandOptions _executeCommandOptions = new ExecuteCommandOptions();
        final Procedure1<ExecuteCommandOptions> _function_1 = (ExecuteCommandOptions it_1) -> {
            it_1.setCommands(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(command)));
        };
        ExecuteCommandOptions _doubleArrow = ObjectExtensions.<ExecuteCommandOptions>operator_doubleArrow(_executeCommandOptions, _function_1);
        it.setRegisterOptions(_doubleArrow);
    };
    final Registration reg = ObjectExtensions.<Registration>operator_doubleArrow(_registration, _function);
    RegistrationParams _registrationParams = new RegistrationParams();
    final Procedure1<RegistrationParams> _function_1 = (RegistrationParams it) -> {
        it.setRegistrations(CollectionLiterals.<Registration>newArrayList(reg));
    };
    RegistrationParams _doubleArrow = ObjectExtensions.<RegistrationParams>operator_doubleArrow(_registrationParams, _function_1);
    this.client.registerCapability(_doubleArrow);
    this.registeredCommands.put(command, service);
    final IDisposable _function_2 = () -> {
        Unregistration _unregistration = new Unregistration();
        final Procedure1<Unregistration> _function_3 = (Unregistration it) -> {
            it.setId(requestId);
            it.setMethod(ExecutableCommandRegistry.METHOD);
        };
        final Unregistration unReg = ObjectExtensions.<Unregistration>operator_doubleArrow(_unregistration, _function_3);
        UnregistrationParams _unregistrationParams = new UnregistrationParams();
        final Procedure1<UnregistrationParams> _function_4 = (UnregistrationParams it) -> {
            it.setUnregisterations(CollectionLiterals.<Unregistration>newArrayList(unReg));
        };
        UnregistrationParams _doubleArrow_1 = ObjectExtensions.<UnregistrationParams>operator_doubleArrow(_unregistrationParams, _function_4);
        this.client.unregisterCapability(_doubleArrow_1);
        this.registeredCommands.remove(command, service);
    };
    return _function_2;
}
Also used : UnregistrationParams(org.eclipse.lsp4j.UnregistrationParams) RegistrationParams(org.eclipse.lsp4j.RegistrationParams) Registration(org.eclipse.lsp4j.Registration) Unregistration(org.eclipse.lsp4j.Unregistration) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) IDisposable(org.eclipse.xtext.util.IDisposable)

Aggregations

IDisposable (org.eclipse.xtext.util.IDisposable)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 ClientCapabilities (org.eclipse.lsp4j.ClientCapabilities)1 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)1 ExecuteCommandOptions (org.eclipse.lsp4j.ExecuteCommandOptions)1 ExecuteCommandParams (org.eclipse.lsp4j.ExecuteCommandParams)1 Registration (org.eclipse.lsp4j.Registration)1 RegistrationParams (org.eclipse.lsp4j.RegistrationParams)1 Unregistration (org.eclipse.lsp4j.Unregistration)1 UnregistrationParams (org.eclipse.lsp4j.UnregistrationParams)1 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)1 ExecutableCommandRegistry (org.eclipse.xtext.ide.server.commands.ExecutableCommandRegistry)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 Test (org.junit.Test)1