org.contextmapper.dsl.ide.commands.CMLCommandService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of context-mapper-lsp Show documentation
Show all versions of context-mapper-lsp Show documentation
Use the ContextMapper language server (LSP) to integrate the ContextMapper DSL within your IDE.
The newest version!
/**
* Copyright 2020 The Context Mapper Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.contextmapper.dsl.ide.commands;
import com.google.common.collect.Lists;
import com.google.gson.JsonPrimitive;
import com.google.inject.Inject;
import java.util.List;
import java.util.function.Function;
import org.apache.log4j.Logger;
import org.contextmapper.dsl.cml.CMLResource;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.xtext.ide.server.ILanguageServerAccess;
import org.eclipse.xtext.ide.server.commands.IExecutableCommandService;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class CMLCommandService implements IExecutableCommandService {
private static final Logger LOG = Logger.getLogger(CMLCommandService.class);
public static final String COMMAND_EXECUTED_RETURN_VALUE = "Command executed.";
public static final String COMMAND_EXECUTION_ERROR_PREFIX = "Error occurred:";
@Inject
private CMLCommandRegistry commandRegistry;
@Override
public List initialize() {
return Lists.newLinkedList(this.commandRegistry.getCommandIds());
}
@Override
public Object execute(final ExecuteCommandParams params, final ILanguageServerAccess access, final CancelIndicator cancelIndicator) {
try {
final CMLResourceCommand command = this.commandRegistry.getCommand(params.getCommand());
if ((command == null)) {
return "Unknown command ID!";
}
Object _head = IterableExtensions.
© 2015 - 2024 Weber Informatics LLC | Privacy Policy