From ddcf27e976cd53dcf9ec562e4c6e1fe6278ac490 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Tue, 3 May 2022 11:56:47 -0400 Subject: [PATCH] Test harness support CodeAction --- .../testharness/CodeAction.java | 32 ++++++++++++------- .../testharness/LanguageServerHarness.java | 5 ++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/CodeAction.java b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/CodeAction.java index 6117a2bed..f060ad9de 100644 --- a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/CodeAction.java +++ b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/CodeAction.java @@ -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 ca; private LanguageServerHarness harness; - public CodeAction(LanguageServerHarness harness, Command command) { + public CodeAction(LanguageServerHarness harness, Either 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"); + } + } } } diff --git a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java index 99b08a9a4..acfac7c7f 100644 --- a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java +++ b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java @@ -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> 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()); }