Search in sources :

Example 1 with IExecutableCommandService

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

the class ExecutableCommandRegistry method initialize.

public void initialize(final Iterable<? extends IResourceServiceProvider> allLanguages, final ClientCapabilities capabilities, final LanguageClient client) {
    this.client = client;
    this.registeredCommands = HashMultimap.<String, IExecutableCommandService>create();
    Boolean _elvis = null;
    WorkspaceClientCapabilities _workspace = capabilities.getWorkspace();
    ExecuteCommandCapabilities _executeCommand = null;
    if (_workspace != null) {
        _executeCommand = _workspace.getExecuteCommand();
    }
    Boolean _dynamicRegistration = null;
    if (_executeCommand != null) {
        _dynamicRegistration = _executeCommand.getDynamicRegistration();
    }
    if (_dynamicRegistration != null) {
        _elvis = _dynamicRegistration;
    } else {
        _elvis = Boolean.valueOf(false);
    }
    final boolean hasDynamicRegistration = (boolean) _elvis;
    for (final IResourceServiceProvider lang : allLanguages) {
        {
            final IExecutableCommandService service = lang.<IExecutableCommandService>get(IExecutableCommandService.class);
            if ((service != null)) {
                final List<String> commands = service.initialize();
                for (final String c : commands) {
                    this.registeredCommands.put(c, service);
                }
                if (hasDynamicRegistration) {
                    final Function1<String, IDisposable> _function = (String command) -> {
                        return this.register(command, service);
                    };
                    service.initializeDynamicRegistration(_function);
                }
            }
        }
    }
}
Also used : WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IExecutableCommandService(org.eclipse.xtext.ide.server.commands.IExecutableCommandService) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities)

Example 2 with IExecutableCommandService

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

the class ExecutableCommandRegistry method executeCommand.

public Object executeCommand(final ExecuteCommandParams params, final ILanguageServerAccess access, final CancelIndicator cancelIndicator) {
    Object result = null;
    Collection<IExecutableCommandService> _get = this.registeredCommands.get(params.getCommand());
    for (final IExecutableCommandService service : _get) {
        {
            final Object localResult = service.execute(params, access, cancelIndicator);
            if ((localResult != null)) {
                if ((result != null)) {
                    StringConcatenation _builder = new StringConcatenation();
                    _builder.append("Multiple commands \'");
                    String _command = params.getCommand();
                    _builder.append(_command);
                    _builder.append("\' have been registered. All are executed but only one result will be send back.");
                    ExecutableCommandRegistry.LOG.error(_builder);
                } else {
                    result = localResult;
                }
            }
        }
    }
    return result;
}
Also used : IExecutableCommandService(org.eclipse.xtext.ide.server.commands.IExecutableCommandService) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

IExecutableCommandService (org.eclipse.xtext.ide.server.commands.IExecutableCommandService)2 List (java.util.List)1 ExecuteCommandCapabilities (org.eclipse.lsp4j.ExecuteCommandCapabilities)1 WorkspaceClientCapabilities (org.eclipse.lsp4j.WorkspaceClientCapabilities)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1