Search in sources :

Example 1 with CommandEventParameter

use of org.eclipse.lsp4e.command.internal.CommandEventParameter in project lsp4e by eclipse.

the class CommandExecutor method createEclipseCoreCommand.

private static ParameterizedCommand createEclipseCoreCommand(@NonNull Command command, IPath context, @NonNull IWorkbench workbench) {
    // Usually commands are defined via extension point, but we synthesize one on
    // the fly for the command ID, since we do not want downstream users
    // having to define them.
    String commandId = command.getCommand();
    @Nullable ICommandService commandService = workbench.getService(ICommandService.class);
    org.eclipse.core.commands.Command coreCommand = commandService.getCommand(commandId);
    if (!coreCommand.isDefined()) {
        ParameterType commandParamType = commandService.getParameterType(LSP_COMMAND_PARAMETER_TYPE_ID);
        ParameterType pathParamType = commandService.getParameterType(LSP_PATH_PARAMETER_TYPE_ID);
        Category category = commandService.getCategory(LSP_COMMAND_CATEGORY_ID);
        IParameter[] parameters = { new CommandEventParameter(commandParamType, command.getTitle(), LSP_COMMAND_PARAMETER_ID), new CommandEventParameter(pathParamType, command.getTitle(), LSP_PATH_PARAMETER_ID) };
        coreCommand.define(commandId, null, category, parameters);
    }
    Map<Object, Object> parameters = new HashMap<>();
    parameters.put(LSP_COMMAND_PARAMETER_ID, command);
    parameters.put(LSP_PATH_PARAMETER_ID, context);
    ParameterizedCommand parameterizedCommand = ParameterizedCommand.generateCommand(coreCommand, parameters);
    return parameterizedCommand;
}
Also used : ParameterType(org.eclipse.core.commands.ParameterType) IParameter(org.eclipse.core.commands.IParameter) Category(org.eclipse.core.commands.Category) HashMap(java.util.HashMap) CommandEventParameter(org.eclipse.lsp4e.command.internal.CommandEventParameter) ICommandService(org.eclipse.ui.commands.ICommandService) JsonObject(com.google.gson.JsonObject) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 Category (org.eclipse.core.commands.Category)1 IParameter (org.eclipse.core.commands.IParameter)1 ParameterType (org.eclipse.core.commands.ParameterType)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 CommandEventParameter (org.eclipse.lsp4e.command.internal.CommandEventParameter)1 ICommandService (org.eclipse.ui.commands.ICommandService)1