Test harness support CodeAction

This commit is contained in:
BoykoAlex
2022-05-03 11:56:47 -04:00
parent b85f86bc5f
commit ddcf27e976
2 changed files with 22 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* Copyright (c) 2017, 2022 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,12 +10,8 @@
*******************************************************************************/
package org.springframework.ide.vscode.languageserver.testharness;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.eclipse.lsp4j.Command;
import org.springframework.ide.vscode.commons.util.Assert;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
/**
* Wrapper for the test harness to refer to and manipulate a
@@ -23,27 +19,39 @@ import org.springframework.ide.vscode.commons.util.Assert;
*/
public class CodeAction {
public final Command command;
public final Either<Command, org.eclipse.lsp4j.CodeAction> ca;
private LanguageServerHarness harness;
public CodeAction(LanguageServerHarness harness, Command command) {
public CodeAction(LanguageServerHarness harness, Either<Command, org.eclipse.lsp4j.CodeAction> ca) {
super();
this.harness = harness;
this.command = command;
this.ca = ca;
}
@Override
public String toString() {
return command.toString();
return ca.toString();
}
public String getLabel() {
return command.getTitle();
return ca.isLeft() ? ca.getLeft().getTitle() : ca.getRight().getTitle();
}
public void perform() throws Exception {
harness.perform(command);
if (ca.isLeft()) {
harness.perform(ca.getLeft());
} else {
org.eclipse.lsp4j.CodeAction codeAction = ca.getRight();
if (codeAction.getCommand() != null) {
harness.perform(codeAction.getCommand());
} else if (codeAction.getEdit() != null) {
// apply workspace edit
throw new UnsupportedOperationException("CodeAction workspaceEdit not yet supported");
} else {
throw new UnsupportedOperationException("resolve/codeAction not yet supported");
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 Pivotal, Inc.
* Copyright (c) 2016, 2022 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -748,8 +748,7 @@ public class LanguageServerHarness {
List<Either<Command, org.eclipse.lsp4j.CodeAction>> actions =
getServer().getTextDocumentService().codeAction(new CodeActionParams(doc.getId(), problem.getRange(), context)).get();
return actions.stream()
.map(e -> e.getLeft())
.map((command) -> new CodeAction(this, command))
.map(e -> new CodeAction(this, e))
.collect(Collectors.toList());
}