
org.contextmapper.dsl.ide.actions.CMLActionService Maven / Gradle / Ivy
/**
* 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.actions;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.contextmapper.dsl.cml.CMLResourceContainer;
import org.contextmapper.dsl.ide.actions.CMLActionRegistry;
import org.contextmapper.dsl.ide.actions.SelectionContextResolver;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.ListExtensions;
@SuppressWarnings("all")
public class CMLActionService implements ICodeActionService2 {
@Inject
private SelectionContextResolver selectionResolver;
@Inject
private CMLActionRegistry actionRegistry;
@Override
public List> getCodeActions(final ICodeActionService2.Options options) {
final CodeActionParams params = options.getCodeActionParams();
final Range currentSelectionRange = params.getRange();
final Position startPosition = currentSelectionRange.getStart();
final Position endPosition = currentSelectionRange.getEnd();
XtextResource _resource = options.getResource();
final CMLResourceContainer resource = new CMLResourceContainer(_resource);
final List selectedObjects = this.selectionResolver.resolveAllSelectedEObjects(resource,
options.getDocument().getOffSet(startPosition), options.getDocument().getOffSet(endPosition));
final LinkedList> allActions = Lists.>newLinkedList();
final Function1> _function = (Command it) -> {
return Either.forLeft(it);
};
allActions.addAll(ListExtensions.map(this.actionRegistry.getApplicableActionCommands(resource, selectedObjects), _function));
boolean _isEmpty = params.getContext().getDiagnostics().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
List _diagnostics = params.getContext().getDiagnostics();
for (final Diagnostic d : _diagnostics) {
final Function> _function_1 = (CodeAction it) -> {
return Either.forRight(it);
};
allActions.addAll(this.actionRegistry.getApplicableQuickfixes(d, options).stream().>map(_function_1).collect(Collectors.>toList()));
}
}
return allActions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy