You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by db...@apache.org on 2022/06/02 09:21:30 UTC
[netbeans] branch master updated: LSP: Initial support for multi-step inputs added. (#4159)
This is an automated email from the ASF dual-hosted git repository.
dbalek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 24ba101a62 LSP: Initial support for multi-step inputs added. (#4159)
24ba101a62 is described below
commit 24ba101a622847fb4afd92f9a84544cd9452ff04
Author: Dusan Balek <du...@oracle.com>
AuthorDate: Thu Jun 2 11:21:24 2022 +0200
LSP: Initial support for multi-step inputs added. (#4159)
---
.../java/lsp/server/db/DBAddConnection.java | 243 +++++++++++++--------
.../debugging/attach/AttachConfigurations.java | 4 +-
.../attach/AttachNativeConfigurations.java | 4 +-
.../java/lsp/server/input/InputBoxStep.java | 148 +++++++++++++
.../java/lsp/server/input/InputCallbackParams.java | 152 +++++++++++++
.../InputService.java} | 22 +-
.../java/lsp/server/input/LspInputServiceImpl.java | 63 ++++++
.../server/{protocol => input}/QuickPickItem.java | 6 +-
.../java/lsp/server/input/QuickPickStep.java | 150 +++++++++++++
.../{protocol => input}/ShowInputBoxParams.java | 52 +++--
.../lsp/server/input/ShowMutliStepInputParams.java | 123 +++++++++++
.../{protocol => input}/ShowQuickPickParams.java | 33 ++-
.../lsp/server/protocol/ConstructorGenerator.java | 100 ++++-----
.../server/protocol/DelegateMethodGenerator.java | 169 +++++++-------
.../server/protocol/EqualsHashCodeGenerator.java | 11 +-
.../lsp/server/protocol/GetterSetterGenerator.java | 11 +-
.../protocol/ImplementOverrideMethodGenerator.java | 6 +-
.../java/lsp/server/protocol/LoggerGenerator.java | 3 +-
.../java/lsp/server/protocol/LspTemplateUI.java | 7 +-
.../lsp/server/protocol/NbCodeClientWrapper.java | 13 +-
.../lsp/server/protocol/NbCodeLanguageClient.java | 17 +-
.../java/lsp/server/protocol/NbLanguageServer.java | 3 +
.../modules/java/lsp/server/protocol/Server.java | 20 ++
.../java/lsp/server/protocol/SurroundWithHint.java | 2 +-
.../lsp/server/protocol/ToStringGenerator.java | 4 +-
.../lsp/server/protocol/WorkspaceUIContext.java | 3 +
.../ChangeMethodParametersRefactoring.java | 2 +-
.../ExtractSuperclassOrInterfaceRefactoring.java | 8 +-
.../lsp/server/refactoring/PullUpRefactoring.java | 10 +-
.../server/refactoring/PushDownRefactoring.java | 6 +-
.../lsp/server/ui/NotifyDescriptorAdapter.java | 8 +-
.../modules/java/lsp/server/ui/UIContext.java | 6 +-
.../java/lsp/server/TestCodeLanguageClient.java | 14 +-
.../java/lsp/server/explorer/ProjectViewTest.java | 14 +-
.../server/progress/TestProgressHandlerTest.java | 6 +-
.../java/lsp/server/protocol/ServerTest.java | 67 ++++--
.../lsp/server/ui/AbstractDialogDisplayerTest.java | 6 +-
java/java.lsp.server/vscode/src/extension.ts | 49 ++++-
java/java.lsp.server/vscode/src/protocol.ts | 40 ++++
java/java.lsp.server/vscode/src/utils.ts | 207 ++++++++++++++++++
40 files changed, 1469 insertions(+), 343 deletions(-)
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java
index 414e78ce6b..351857c2bc 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java
@@ -36,20 +36,24 @@ import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.db.explorer.ConnectionManager;
import org.netbeans.api.db.explorer.DatabaseConnection;
import org.netbeans.api.db.explorer.DatabaseException;
import org.netbeans.api.db.explorer.JDBCDriver;
import org.netbeans.api.db.explorer.JDBCDriverManager;
+import org.netbeans.modules.java.lsp.server.input.InputBoxStep;
+import org.netbeans.modules.java.lsp.server.input.LspInputServiceImpl;
import org.netbeans.modules.java.lsp.server.protocol.CodeActionsProvider;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.QuickPickStep;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.parsing.api.ResultIterator;
-import org.openide.awt.StatusDisplayer;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.URLMapper;
+import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
@@ -58,6 +62,7 @@ import org.openide.util.lookup.ServiceProvider;
* @author Jan Horvath
*/
@NbBundle.Messages({
+ "MSG_AddDBConnection=Add Database Connection",
"MSG_EnterDbUrl=Enter DB URL",
"MSG_EnterUsername=Enter Username",
"MSG_EnterPassword=Enter Password",
@@ -93,44 +98,58 @@ public class DBAddConnection extends CodeActionsProvider {
if (!DB_ADD_CONNECTION.equals(command)) {
return null;
}
+ LspInputServiceImpl inputService = Lookup.getDefault().lookup(LspInputServiceImpl.class);
+ if (inputService == null) {
+ return null;
+ }
- String userId = null;
- String dbUrl = null;
- String driverClass = null;
- if (arguments != null && arguments.size() > 0) {
+ if (arguments != null && !arguments.isEmpty()) {
final Map m = gson.fromJson((JsonObject) arguments.get(0), Map.class);
- if (m != null) {
- userId = (String) m.get(USER_ID);
- dbUrl = (String) m.get(DB_URL);
- driverClass = (String) m.get(DRIVER);
- }
+ String userId = m != null ? (String) m.get(USER_ID) : null;
+ String password = m != null ? (String) m.get(PASSWORD) : null;
+ String dbUrl = m != null ? (String) m.get(DB_URL) : null;
+ String driverClass = m != null ? (String) m.get(DRIVER) : null;
if (dbUrl != null && driverClass != null) {
JDBCDriver[] driver = JDBCDriverManager.getDefault().getDrivers(driverClass); //NOI18N
if (driver != null && driver.length > 0) {
- CompletableFuture<String> usernameFuture = userId != null ? CompletableFuture.completedFuture(userId) : client.showInputBox(new ShowInputBoxParams(
- Bundle.MSG_EnterUsername(), userId));
-
- usernameFuture.thenAccept((username) -> { //NOI18N
- if (username == null) {
- return;
- }
- String password = (String) m.get(PASSWORD);
- CompletableFuture<String> passwordFuture = password != null ? CompletableFuture.completedFuture(password) : client.showInputBox(new ShowInputBoxParams(
- Bundle.MSG_EnterPassword(), "", true));
- passwordFuture.thenAccept((p) -> { //NOI18N
- if (p == null) {
- return;
+ if (userId == null || password == null) {
+ String inuptId = inputService.registerInput(param -> {
+ int totalSteps = 2;
+ switch (param.getStep()) {
+ case 1:
+ return CompletableFuture.completedFuture(Either.forRight(new InputBoxStep(totalSteps, USER_ID, Bundle.MSG_EnterUsername(), userId)));
+ case 2:
+ Map<String, Either<List<QuickPickItem>, String>> data = param.getData();
+ Either<List<QuickPickItem>, String> userData = data.get(USER_ID);
+ if (userData != null) {
+ return CompletableFuture.completedFuture(Either.forRight(new InputBoxStep(totalSteps, PASSWORD, null, Bundle.MSG_EnterUsername(), password, true)));
+ }
+ return CompletableFuture.completedFuture(null);
+ default:
+ return CompletableFuture.completedFuture(null);
}
- DatabaseConnection dbconn = DatabaseConnection.create(driver[0], (String) m.get(DB_URL), username, (String) m.get(SCHEMA), p, true, (String) m.get(DISPLAY_NAME));
+ }, null);
+ client.showMultiStepInput(new ShowMutliStepInputParams(userId, Bundle.MSG_AddDBConnection())).thenAccept(result -> {
+ Either<List<QuickPickItem>, String> userData = result.get(USER_ID);
+ Either<List<QuickPickItem>, String> passwordData = result.get(PASSWORD);
+ DatabaseConnection dbconn = DatabaseConnection.create(driver[0], dbUrl, userData.getRight(), (String) m.get(SCHEMA), passwordData.getRight(), true, (String) m.get(DISPLAY_NAME));
try {
ConnectionManager.getDefault().addConnection(dbconn);
+ client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
} catch (DatabaseException ex) {
client.showMessage(new MessageParams(MessageType.Error, ex.getMessage()));
}
});
- });
- client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
+ } else {
+ DatabaseConnection dbconn = DatabaseConnection.create(driver[0], dbUrl, userId, (String) m.get(SCHEMA), password, true, (String) m.get(DISPLAY_NAME));
+ try {
+ ConnectionManager.getDefault().addConnection(dbconn);
+ client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
+ } catch (DatabaseException ex) {
+ client.showMessage(new MessageParams(MessageType.Error, ex.getMessage()));
+ }
+ }
}
return CompletableFuture.completedFuture(null);
}
@@ -149,77 +168,109 @@ public class DBAddConnection extends CodeActionsProvider {
}
}
}
-
- return client.showQuickPick(new ShowQuickPickParams(Bundle.MSG_SelectDriver(), false, items))
- .thenApply(selectedItems -> {
- if (selectedItems == null) {
- return null;
+ if (items.isEmpty()) {
+ client.showMessage(new MessageParams(MessageType.Error, Bundle.MSG_DriverNotFound()));
+ } else {
+ List<String> schemas = new ArrayList<>();
+ String inputId = inputService.registerInput(params -> {
+ Map<String, Either<List<QuickPickItem>, String>> data = params.getData();
+ int totalSteps = 4;
+ switch (params.getStep()) {
+ case 1:
+ return CompletableFuture.completedFuture(Either.forLeft(new QuickPickStep(totalSteps, DRIVER, Bundle.MSG_SelectDriver(), items)));
+ case 2: {
+ Either<List<QuickPickItem>,String> driverData = data.get(DRIVER);
+ if (driverData != null && !driverData.getLeft().isEmpty()) {
+ int i = ((Double) driverData.getLeft().get(0).getUserData()).intValue();
+ JDBCDriver driver = drivers[i];
+ String urlTemplate = driver.getClassName() != null ? urlTemplates.get(driver.getClassName()) : "";
+ if (urlTemplate == null) {
+ urlTemplate = "";
+ }
+ return CompletableFuture.completedFuture(Either.forRight(new InputBoxStep(totalSteps, DB_URL, Bundle.MSG_EnterDbUrl(), urlTemplate)));
+ }
+ return CompletableFuture.completedFuture(null);
}
- if (!selectedItems.isEmpty()) {
- int i = ((Double) selectedItems.get(0).getUserData()).intValue();
- JDBCDriver driver = drivers[i];
- String urlTemplate = driver.getClassName() != null ? urlTemplates.get(driver.getClassName()) : "";
- if (urlTemplate == null) {
- urlTemplate = "";
+ case 3: {
+ Either<List<QuickPickItem>,String> urlData = data.get(DB_URL);
+ if (urlData != null && !urlData.getRight().isEmpty()) {
+ return CompletableFuture.completedFuture(Either.forRight(new InputBoxStep(totalSteps, USER_ID, Bundle.MSG_EnterUsername(), "")));
}
- client.showInputBox(new ShowInputBoxParams(
- Bundle.MSG_EnterDbUrl(), urlTemplate)).thenAccept((u) -> {
- if (u == null) {
- return;
+ return CompletableFuture.completedFuture(null);
+ }
+ case 4: {
+ Either<List<QuickPickItem>,String> userData = data.get(USER_ID);
+ if (userData != null && !userData.getRight().isEmpty()) {
+ return CompletableFuture.completedFuture(Either.forRight(new InputBoxStep(totalSteps, PASSWORD, null, Bundle.MSG_EnterPassword(), "", true)));
+ }
+ return CompletableFuture.completedFuture(null);
+ }
+ case 5: {
+ Either<List<QuickPickItem>,String> passwordData = data.get(PASSWORD);
+ if (passwordData != null) {
+ if (schemas.isEmpty()) {
+ client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
+ return CompletableFuture.completedFuture(null);
+ } else {
+ List<QuickPickItem> schemaItems = schemas.stream().map(schema -> new QuickPickItem(schema)).collect(Collectors.toList());
+ return CompletableFuture.completedFuture(Either.forLeft(new QuickPickStep(totalSteps + 1, SCHEMA, Bundle.MSG_SelectSchema(), schemaItems)));
}
- client.showInputBox(new ShowInputBoxParams(
- Bundle.MSG_EnterUsername(), "")).thenAccept((username) -> { //NOI18N
- if (username == null) {
- return;
- }
- client.showInputBox(new ShowInputBoxParams(
- Bundle.MSG_EnterPassword(), "", true)).thenAccept((password) -> { //NOI18N
- if (password == null) {
- return;
- }
- DatabaseConnection dbconn = DatabaseConnection.create(driver, u, username, null, password, true);
- try {
- ConnectionManager.getDefault().addConnection(dbconn);
- List<String> schemas = getSchemas(dbconn);
- if (schemas.isEmpty()) {
- client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
- } else {
- List<QuickPickItem> schemaItems = schemas.stream().map(schema -> new QuickPickItem(schema)).collect(Collectors.toList());
- client.showQuickPick(new ShowQuickPickParams(Bundle.MSG_SelectSchema(), schemaItems)).thenAccept((s) -> {
- if (s == null) {
- try {
- // Command was interrupted, we don't want the connection to be added
- ConnectionManager.getDefault().removeConnection(dbconn);
- } catch (DatabaseException ex) {
- StatusDisplayer.getDefault().setStatusText(ex.getMessage());
- }
- return;
- }
- String schema = s.get(0).getLabel();
- DatabaseConnection dbconn1 = DatabaseConnection.create(driver, u, username, schema, password, true);
- try {
- ConnectionManager.getDefault().removeConnection(dbconn);
- ConnectionManager.getDefault().addConnection(dbconn1);
- } catch (DatabaseException ex) {
- client.showMessage(new MessageParams(MessageType.Error, ex.getMessage()));
- return;
- }
- client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
- });
- }
- } catch (SQLException | DatabaseException ex) {
- client.showMessage(new MessageParams(MessageType.Error, ex.getMessage()));
- }
- });
- });
-
- });
-
- } else {
- client.showMessage(new MessageParams(MessageType.Error, Bundle.MSG_DriverNotFound()));
+ }
+ return CompletableFuture.completedFuture(null);
+ }
+ default:
+ return CompletableFuture.completedFuture(null);
+ }
+ }, params -> {
+ Map<String, Either<List<QuickPickItem>, String>> data = params.getData();
+ switch (params.getStep()) {
+ case 4:
+ Either<List<QuickPickItem>,String> passwordData = data.get(PASSWORD);
+ if (passwordData != null && !passwordData.getRight().isEmpty()) {
+ Either<List<QuickPickItem>,String> driverData = data.get(DRIVER);
+ Either<List<QuickPickItem>,String> urlData = data.get(DB_URL);
+ Either<List<QuickPickItem>,String> userData = data.get(USER_ID);
+ int i = ((Double) driverData.getLeft().get(0).getUserData()).intValue();
+ JDBCDriver driver = drivers[i];
+ schemas.clear();
+ DatabaseConnection dbconn = DatabaseConnection.create(driver, urlData.getRight(), userData.getRight(), null, passwordData.getRight(), true);
+ try {
+ ConnectionManager.getDefault().addConnection(dbconn);
+ schemas.addAll(getSchemas(dbconn));
+ } catch(DatabaseException | SQLException ex) {
+ return CompletableFuture.completedFuture(ex.getMessage());
+ } finally {
+ try {
+ ConnectionManager.getDefault().removeConnection(dbconn);
+ } catch (DatabaseException ex) {}
+ }
+ }
+ break;
+ }
+ return CompletableFuture.completedFuture(null);
+ });
+ return client.showMultiStepInput(new ShowMutliStepInputParams(inputId, Bundle.MSG_AddDBConnection())).thenApply(result -> {
+ Either<List<QuickPickItem>,String> driverData = result.get(DRIVER);
+ Either<List<QuickPickItem>,String> urlData = result.get(DB_URL);
+ Either<List<QuickPickItem>,String> userData = result.get(USER_ID);
+ Either<List<QuickPickItem>,String> passwordData = result.get(PASSWORD);
+ Either<List<QuickPickItem>,String> schemaData = result.get(SCHEMA);
+ if (driverData != null && urlData != null && userData != null && passwordData != null && schemaData != null && !schemaData.getLeft().isEmpty()) {
+ int i = ((Double) driverData.getLeft().get(0).getUserData()).intValue();
+ JDBCDriver driver = drivers[i];
+ String schema = schemaData.getLeft().get(0).getLabel();
+ DatabaseConnection dbconn = DatabaseConnection.create(driver, urlData.getRight(), userData.getRight(), schema, passwordData.getRight(), true);
+ try {
+ ConnectionManager.getDefault().addConnection(dbconn);
+ } catch (DatabaseException ex) {
+ client.showMessage(new MessageParams(MessageType.Error, ex.getMessage()));
}
- return null;
- });
+ client.showMessage(new MessageParams(MessageType.Info, Bundle.MSG_ConnectionAdded()));
+ }
+ return null;
+ });
+ }
+ return null;
}
private static List<String> getSchemas(DatabaseConnection dbconn) throws SQLException, DatabaseException {
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachConfigurations.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachConfigurations.java
index 4444f5ccfc..6e501784cb 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachConfigurations.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachConfigurations.java
@@ -40,8 +40,8 @@ import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
import org.netbeans.modules.java.lsp.server.debugging.utils.ErrorUtilities;
import org.netbeans.modules.java.lsp.server.protocol.DebugConnector;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.openide.util.NbBundle.Messages;
import org.openide.util.RequestProcessor;
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachNativeConfigurations.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachNativeConfigurations.java
index 3011f20a7a..c65048ac5b 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachNativeConfigurations.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/attach/AttachNativeConfigurations.java
@@ -27,8 +27,8 @@ import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
import org.netbeans.modules.java.lsp.server.debugging.attach.Processes.ProcessInfo;
import org.netbeans.modules.java.lsp.server.debugging.utils.ErrorUtilities;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputBoxStep.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputBoxStep.java
new file mode 100644
index 0000000000..bac8476930
--- /dev/null
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputBoxStep.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.modules.java.lsp.server.input;
+
+import java.util.Objects;
+import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
+import org.eclipse.lsp4j.util.Preconditions;
+import org.eclipse.xtext.xbase.lib.Pure;
+import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+public class InputBoxStep extends ShowInputBoxParams {
+
+ /**
+ * An optional total step count.
+ */
+ private int totalSteps;
+
+ /**
+ * Current step id. Used to retrieve step result.
+ */
+ @NonNull
+ private String stepId;
+
+ public InputBoxStep() {
+ super();
+ this.totalSteps = 0;
+ }
+
+ public InputBoxStep(final int totalSteps, @NonNull final String stepId, @NonNull final String prompt, @NonNull final String value) {
+ super(prompt, value);
+ this.totalSteps = totalSteps;
+ this.stepId = Preconditions.checkNotNull(stepId, "stepId");
+ }
+
+ public InputBoxStep(final int totalSteps, @NonNull final String stepId, final String title, @NonNull final String prompt, @NonNull final String value, final boolean password) {
+ super(title, prompt, value, password);
+ this.totalSteps = totalSteps;
+ this.stepId = Preconditions.checkNotNull(stepId, "stepId");
+ }
+
+ /**
+ * An optional total step count.
+ */
+ @Pure
+ public int getTotalSteps() {
+ return totalSteps;
+ }
+
+ /**
+ * An optional total step count.
+ */
+ public void setTotalSteps(final int totalSteps) {
+ this.totalSteps = totalSteps;
+ }
+
+ /**
+ * Current step id. Used to retrieve step result.
+ */
+ @Pure
+ @NonNull
+ public String getStepId() {
+ return stepId;
+ }
+
+ /**
+ * Current step id. Used to retrieve step result.
+ */
+ public void setStepId(@NonNull final String stepId) {
+ this.stepId = Preconditions.checkNotNull(stepId, "stepId");
+ }
+
+ @Override
+ @Pure
+ public String toString() {
+ ToStringBuilder b = new ToStringBuilder(this);
+ b.add("totalSteps", totalSteps);
+ b.add("stepId", stepId);
+ b.add("title", getTitle());
+ b.add("prompt", getPrompt());
+ b.add("value", getValue());
+ b.add("password" , isPassword());
+ return b.toString();
+ }
+
+ @Override
+ @Pure
+ public int hashCode() {
+ int hash = 7;
+ hash = 97 * hash + this.totalSteps;
+ hash = 97 * hash + Objects.hashCode(this.stepId);
+ hash = 97 * hash + Objects.hashCode(this.getTitle());
+ hash = 97 * hash + Objects.hashCode(this.getPrompt());
+ hash = 97 * hash + Objects.hashCode(this.getValue());
+ hash = 97 * hash + (this.isPassword() ? 1 : 0);
+ return hash;
+ }
+
+ @Override
+ @Pure
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final InputBoxStep other = (InputBoxStep) obj;
+ if (this.totalSteps != other.totalSteps) {
+ return false;
+ }
+ if (this.isPassword() != other.isPassword()) {
+ return false;
+ }
+ if (!Objects.equals(this.stepId, other.stepId)) {
+ return false;
+ }
+ if (!Objects.equals(this.getTitle(), other.getTitle())) {
+ return false;
+ }
+ if (!Objects.equals(this.getPrompt(), other.getPrompt())) {
+ return false;
+ }
+ return Objects.equals(this.getValue(), other.getValue());
+ }
+}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputCallbackParams.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputCallbackParams.java
new file mode 100644
index 0000000000..f5dc05e2e9
--- /dev/null
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputCallbackParams.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.modules.java.lsp.server.input;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
+import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
+import org.eclipse.lsp4j.util.Preconditions;
+import org.eclipse.xtext.xbase.lib.Pure;
+import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+public class InputCallbackParams {
+
+ /**
+ * ID of the input.
+ */
+ @NonNull
+ private String inputId;
+
+ /**
+ * Step number.
+ */
+ private int step;
+
+ /**
+ * Collected input values and selected items.
+ */
+ @NonNull
+ private Map<String, Either<List<QuickPickItem>, String>> data;
+
+ public InputCallbackParams() {
+ this("", 0, new HashMap<>());
+ }
+
+ public InputCallbackParams(@NonNull final String inputId, final int step, @NonNull final Map<String, Either<List<QuickPickItem>, String>> data) {
+ this.inputId = Preconditions.checkNotNull(inputId, "inputId");
+ this.step = step;
+ this.data = Preconditions.checkNotNull(data, "data");
+ }
+
+ /**
+ * ID of the input.
+ */
+ @Pure
+ @NonNull
+ public String getInputId() {
+ return inputId;
+ }
+
+ /**
+ * ID of the input.
+ */
+ public void setInputId(@NonNull final String inputId) {
+ this.inputId = Preconditions.checkNotNull(inputId, "inputId");
+ }
+
+ /**
+ * Step number.
+ */
+ @Pure
+ public int getStep() {
+ return step;
+ }
+
+ /**
+ * Step number.
+ */
+ public void setStep(int step) {
+ this.step = step;
+ }
+
+ /**
+ * Collected input values and selected items.
+ */
+ @Pure
+ @NonNull
+ public Map<String, Either<List<QuickPickItem>, String>> getData() {
+ return data;
+ }
+
+ /**
+ * Collected input values and selected items.
+ */
+ public void setData(@NonNull final Map<String, Either<List<QuickPickItem>, String>> data) {
+ this.data = Preconditions.checkNotNull(data, "data");
+ }
+
+ @Override
+ @Pure
+ public String toString() {
+ ToStringBuilder b = new ToStringBuilder(this);
+ b.add("inputId", inputId);
+ b.add("step", step);
+ b.add("data", data);
+ return b.toString();
+ }
+
+ @Override
+ @Pure
+ public int hashCode() {
+ int hash = 3;
+ hash = 79 * hash + Objects.hashCode(this.inputId);
+ hash = 79 * hash + this.step;
+ hash = 79 * hash + Objects.hashCode(this.data);
+ return hash;
+ }
+
+ @Override
+ @Pure
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final InputCallbackParams other = (InputCallbackParams) obj;
+ if (this.step != other.step) {
+ return false;
+ }
+ if (!Objects.equals(this.inputId, other.inputId)) {
+ return false;
+ }
+ return Objects.equals(this.data, other.data);
+ }
+}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputService.java
similarity index 59%
copy from java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java
copy to java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputService.java
index 539c261d75..ac043e3d2b 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/InputService.java
@@ -16,17 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.netbeans.modules.java.lsp.server.protocol;
+package org.netbeans.modules.java.lsp.server.input;
-import org.eclipse.lsp4j.jsonrpc.services.JsonDelegate;
-import org.eclipse.lsp4j.services.LanguageServer;
-import org.netbeans.modules.java.lsp.server.explorer.api.TreeViewService;
+import java.util.concurrent.CompletableFuture;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
+import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
+import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;
/**
*
- * @author sdedic
+ * @author Dusan Balek
*/
-public interface NbLanguageServer extends LanguageServer {
- @JsonDelegate
- public TreeViewService getTreeViewService();
+@JsonSegment("input")
+public interface InputService {
+
+ @JsonRequest("step")
+ public CompletableFuture<Either<QuickPickStep, InputBoxStep>> step(InputCallbackParams params);
+
+ @JsonRequest("validate")
+ public CompletableFuture<String> validate(InputCallbackParams params);
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/LspInputServiceImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/LspInputServiceImpl.java
new file mode 100644
index 0000000000..c295c676e6
--- /dev/null
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/LspInputServiceImpl.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.modules.java.lsp.server.input;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
+import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+@JsonSegment("input")
+public class LspInputServiceImpl implements InputService {
+
+ private final Map<String, Function<InputCallbackParams, CompletableFuture<Either<QuickPickStep, InputBoxStep>>>> stepCallbacks = new HashMap<>();
+ private final Map<String, Function<InputCallbackParams, CompletableFuture<String>>> validateCallbacks = new HashMap<>();
+
+ public String registerInput(Function<InputCallbackParams, CompletableFuture<Either<QuickPickStep, InputBoxStep>>> stepCallback, Function<InputCallbackParams, CompletableFuture<String>> validateCallback) {
+ String id = "ID:" + System.identityHashCode(stepCallback);
+ stepCallbacks.put(id, stepCallback);
+ if (validateCallback != null) {
+ validateCallbacks.put(id, validateCallback);
+ }
+ return id;
+ }
+
+ public void unregisterInput(String inputId) {
+ stepCallbacks.remove(inputId);
+ validateCallbacks.remove(inputId);
+ }
+
+ @Override
+ public CompletableFuture<Either<QuickPickStep, InputBoxStep>> step(InputCallbackParams params) {
+ Function<InputCallbackParams, CompletableFuture<Either<QuickPickStep, InputBoxStep>>> callback = stepCallbacks.get(params.getInputId());
+ return callback != null ? callback.apply(params) : CompletableFuture.completedFuture(null);
+ }
+
+ @Override
+ public CompletableFuture<String> validate(InputCallbackParams params) {
+ Function<InputCallbackParams, CompletableFuture<String>> callback = validateCallbacks.get(params.getInputId());
+ return callback != null ? callback.apply(params) : CompletableFuture.completedFuture(null);
+ }
+}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/QuickPickItem.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/QuickPickItem.java
similarity index 96%
rename from java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/QuickPickItem.java
rename to java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/QuickPickItem.java
index 633c703370..40ae0082be 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/QuickPickItem.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/QuickPickItem.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.netbeans.modules.java.lsp.server.protocol;
+package org.netbeans.modules.java.lsp.server.input;
import java.util.Objects;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
@@ -168,7 +168,6 @@ public class QuickPickItem {
hash = 83 * hash + Objects.hashCode(this.label);
hash = 83 * hash + Objects.hashCode(this.description);
hash = 83 * hash + Objects.hashCode(this.detail);
- hash = 83 * hash + (this.picked ? 1 : 0);
hash = 83 * hash + Objects.hashCode(this.userData);
return hash;
}
@@ -186,9 +185,6 @@ public class QuickPickItem {
return false;
}
final QuickPickItem other = (QuickPickItem) obj;
- if (this.picked != other.picked) {
- return false;
- }
if (!Objects.equals(this.label, other.label)) {
return false;
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/QuickPickStep.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/QuickPickStep.java
new file mode 100644
index 0000000000..92c8986881
--- /dev/null
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/QuickPickStep.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.modules.java.lsp.server.input;
+
+import java.util.List;
+import java.util.Objects;
+import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
+import org.eclipse.lsp4j.util.Preconditions;
+import org.eclipse.xtext.xbase.lib.Pure;
+import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+public class QuickPickStep extends ShowQuickPickParams {
+
+ /**
+ * An optional total step count.
+ */
+ private int totalSteps;
+
+ /**
+ * Current step id. Used to retrieve step result.
+ */
+ @NonNull
+ private String stepId;
+
+ public QuickPickStep() {
+ super();
+ this.totalSteps = 0;
+ this.stepId = "";
+ }
+
+ public QuickPickStep(final int totalSteps, @NonNull final String stepId, @NonNull final String placeHolder, @NonNull final List<QuickPickItem> items) {
+ super(placeHolder, items);
+ this.totalSteps = totalSteps;
+ this.stepId = Preconditions.checkNotNull(stepId, "stepId");
+ }
+
+ public QuickPickStep(final int totalSteps, @NonNull final String stepId, final String title, @NonNull final String placeHolder, final boolean canPickMany, @NonNull final List<QuickPickItem> items) {
+ super(title, placeHolder, canPickMany, items);
+ this.totalSteps = totalSteps;
+ this.stepId = Preconditions.checkNotNull(stepId, "stepId");
+ }
+
+ /**
+ * An optional total step count.
+ */
+ @Pure
+ public int getTotalSteps() {
+ return totalSteps;
+ }
+
+ /**
+ * An optional total step count.
+ */
+ public void setTotalSteps(final int totalSteps) {
+ this.totalSteps = totalSteps;
+ }
+
+ /**
+ * Current step id. Used to retrieve step result.
+ */
+ @Pure
+ @NonNull
+ public String getStepId() {
+ return stepId;
+ }
+
+ /**
+ * Current step id. Used to retrieve step result.
+ */
+ public void setStepId(@NonNull final String stepId) {
+ this.stepId = Preconditions.checkNotNull(stepId, "stepId");
+ }
+
+ @Override
+ @Pure
+ public String toString() {
+ ToStringBuilder b = new ToStringBuilder(this);
+ b.add("totalSteps", totalSteps);
+ b.add("stepId", stepId);
+ b.add("title", getTitle());
+ b.add("placeHolder", getPlaceHolder());
+ b.add("canPickMany", getCanPickMany());
+ b.add("items", getItems());
+ return b.toString();
+ }
+
+ @Override
+ @Pure
+ public int hashCode() {
+ int hash = 3;
+ hash = 71 * hash + this.totalSteps;
+ hash = 71 * hash + Objects.hashCode(this.stepId);
+ hash = 71 * hash + Objects.hashCode(this.getTitle());
+ hash = 71 * hash + Objects.hashCode(this.getPlaceHolder());
+ hash = 71 * hash + (this.getCanPickMany() ? 1 : 0);
+ hash = 71 * hash + Objects.hashCode(this.getItems());
+ return hash;
+ }
+
+ @Override
+ @Pure
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final QuickPickStep other = (QuickPickStep) obj;
+ if (this.totalSteps != other.totalSteps) {
+ return false;
+ }
+ if (this.getCanPickMany() != other.getCanPickMany()) {
+ return false;
+ }
+ if (!Objects.equals(this.stepId, other.stepId)) {
+ return false;
+ }
+ if (!Objects.equals(this.getTitle(), other.getTitle())) {
+ return false;
+ }
+ if (!Objects.equals(this.getPlaceHolder(), other.getPlaceHolder())) {
+ return false;
+ }
+ return Objects.equals(this.getItems(), other.getItems());
+ }
+}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ShowInputBoxParams.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowInputBoxParams.java
similarity index 79%
rename from java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ShowInputBoxParams.java
rename to java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowInputBoxParams.java
index 0253a8b6fa..17b1fec76e 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ShowInputBoxParams.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowInputBoxParams.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.netbeans.modules.java.lsp.server.protocol;
+package org.netbeans.modules.java.lsp.server.input;
import java.util.Objects;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
@@ -42,6 +42,11 @@ public class ShowInputBoxParams {
*/
@NonNull
private String value;
+
+ /**
+ * An optional title of the input box.
+ */
+ private String title;
/**
* Controls if a password input is shown. Password input hides the typed text.
@@ -53,15 +58,31 @@ public class ShowInputBoxParams {
}
public ShowInputBoxParams(@NonNull final String prompt, @NonNull final String value) {
- this(prompt, value, false);
- }
-
- public ShowInputBoxParams(@NonNull final String prompt, @NonNull final String value, final boolean password) {
this.prompt = Preconditions.checkNotNull(prompt, "prompt");
this.value = Preconditions.checkNotNull(value, "value");
+ }
+
+ public ShowInputBoxParams(final String title, @NonNull final String prompt, @NonNull final String value, final boolean password) {
+ this(prompt, value);
+ this.title = title;
this.password = password;
}
+ /**
+ * An optional title of the input box.
+ */
+ @Pure
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * An optional title of the input box.
+ */
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
/**
* The text to display underneath the input box.
*/
@@ -93,11 +114,9 @@ public class ShowInputBoxParams {
public void setValue(@NonNull final String value) {
this.value = Preconditions.checkNotNull(value, "value");
}
-
+
/**
* Controls if a password input is shown. Password input hides the typed text.
- *
- * @since 1.16
*/
@Pure
@NonNull
@@ -107,8 +126,6 @@ public class ShowInputBoxParams {
/**
* Controls if a password input is shown. Password input hides the typed text.
- *
- * @since 1.16
*/
public void setPassword(boolean password) {
this.password = password;
@@ -118,20 +135,26 @@ public class ShowInputBoxParams {
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
+ b.add("title", title);
b.add("prompt", prompt);
b.add("value", value);
+ b.add("password" , password);
return b.toString();
}
@Override
+ @Pure
public int hashCode() {
int hash = 5;
+ hash = 59 * hash + Objects.hashCode(this.title);
hash = 59 * hash + Objects.hashCode(this.prompt);
hash = 59 * hash + Objects.hashCode(this.value);
+ hash = 59 * hash + (this.password ? 1 : 0);
return hash;
}
@Override
+ @Pure
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -143,12 +166,15 @@ public class ShowInputBoxParams {
return false;
}
final ShowInputBoxParams other = (ShowInputBoxParams) obj;
- if (!Objects.equals(this.prompt, other.prompt)) {
+ if (this.password != other.password) {
return false;
}
- if (!Objects.equals(this.value, other.value)) {
+ if (!Objects.equals(this.title, other.title)) {
+ return false;
+ }
+ if (!Objects.equals(this.prompt, other.prompt)) {
return false;
}
- return true;
+ return Objects.equals(this.value, other.value);
}
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowMutliStepInputParams.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowMutliStepInputParams.java
new file mode 100644
index 0000000000..3c7304db6a
--- /dev/null
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowMutliStepInputParams.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.netbeans.modules.java.lsp.server.input;
+
+import java.util.Objects;
+import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
+import org.eclipse.lsp4j.util.Preconditions;
+import org.eclipse.xtext.xbase.lib.Pure;
+import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+@SuppressWarnings("all")
+public class ShowMutliStepInputParams {
+
+ /**
+ * ID of the input.
+ */
+ @NonNull
+ private String id;
+
+ /**
+ * An optional title.
+ */
+ private String title;
+
+ public ShowMutliStepInputParams() {
+ this("", null);
+ }
+
+ public ShowMutliStepInputParams(@NonNull final String id, final String title) {
+ this.id = Preconditions.checkNotNull(id, "id");
+ this.title = title;
+ }
+
+ /**
+ * ID of the input.
+ */
+ @Pure
+ @NonNull
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * ID of the input.
+ */
+ public void setId(@NonNull final String id) {
+ this.id = Preconditions.checkNotNull(id, "id");
+ }
+
+ /**
+ * An optional title.
+ */
+ @Pure
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * An optional title.
+ */
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
+ @Override
+ @Pure
+ public String toString() {
+ ToStringBuilder b = new ToStringBuilder(this);
+ b.add("id", id);
+ b.add("title", title);
+ return b.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 43 * hash + Objects.hashCode(this.id);
+ hash = 43 * hash + Objects.hashCode(this.title);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final ShowMutliStepInputParams other = (ShowMutliStepInputParams) obj;
+ if (!Objects.equals(this.id, other.id)) {
+ return false;
+ }
+ if (!Objects.equals(this.title, other.title)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ShowQuickPickParams.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowQuickPickParams.java
similarity index 84%
rename from java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ShowQuickPickParams.java
rename to java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowQuickPickParams.java
index 504632913f..30cd38999c 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ShowQuickPickParams.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/input/ShowQuickPickParams.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.netbeans.modules.java.lsp.server.protocol;
+package org.netbeans.modules.java.lsp.server.input;
import java.util.ArrayList;
import java.util.List;
@@ -34,6 +34,11 @@ import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@SuppressWarnings("all")
public class ShowQuickPickParams {
+ /**
+ * An optional title of the quick pick.
+ */
+ private String title;
+
/**
* A string to show as placeholder in the input box to guide the user what to pick on.
*/
@@ -60,11 +65,27 @@ public class ShowQuickPickParams {
this.items = Preconditions.checkNotNull(items, "items");
}
- public ShowQuickPickParams(final String placeHolder, final boolean canPickMany, @NonNull final List<QuickPickItem> items) {
+ public ShowQuickPickParams(final String title, @NonNull final String placeHolder, final boolean canPickMany, @NonNull final List<QuickPickItem> items) {
this(placeHolder, items);
+ this.title = title;
this.canPickMany = canPickMany;
}
+ /**
+ * An optional title of the quick pick.
+ */
+ @Pure
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * An optional title of the quick pick.
+ */
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
/**
* A string to show as placeholder in the input box to guide the user what to pick on.
*/
@@ -116,6 +137,7 @@ public class ShowQuickPickParams {
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
+ b.add("title", title);
b.add("placeHolder", placeHolder);
b.add("canPickMany", canPickMany);
b.add("items", items);
@@ -126,6 +148,7 @@ public class ShowQuickPickParams {
@Pure
public int hashCode() {
int hash = 7;
+ hash = 29 * hash + Objects.hashCode(this.title);
hash = 29 * hash + Objects.hashCode(this.placeHolder);
hash = 29 * hash + (this.canPickMany ? 1 : 0);
hash = 29 * hash + Objects.hashCode(this.items);
@@ -148,12 +171,12 @@ public class ShowQuickPickParams {
if (this.canPickMany != other.canPickMany) {
return false;
}
- if (!Objects.equals(this.placeHolder, other.placeHolder)) {
+ if (!Objects.equals(this.title, other.title)) {
return false;
}
- if (!Objects.equals(this.items, other.items)) {
+ if (!Objects.equals(this.placeHolder, other.placeHolder)) {
return false;
}
- return true;
+ return Objects.equals(this.items, other.items);
}
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java
index 1208936076..ef1e95f04f 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java
@@ -54,13 +54,19 @@ import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.WorkspaceEdit;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.modules.java.editor.codegen.GeneratorUtils;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.LspInputServiceImpl;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.QuickPickStep;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
@@ -173,6 +179,8 @@ public final class ConstructorGenerator extends CodeActionsProvider {
if (constructors.isEmpty() && fields.isEmpty()) {
return Collections.emptyList();
}
+ fields.sort((f1, f2) -> f1.getLabel().compareTo(f2.getLabel()));
+ constructors.sort((c1, c2) -> c1.getLabel().compareTo(c2.getLabel()));
String uri = Utils.toUri(info.getFileObject());
Map<String, Object> data = new HashMap<>();
data.put(URI, uri);
@@ -185,13 +193,14 @@ public final class ConstructorGenerator extends CodeActionsProvider {
@Override
@NbBundle.Messages({
"DN_SelectSuperConstructor=Select super constructor",
+ "DN_SelectConstructorFields=Select fields to be initialized by constructor",
})
public CompletableFuture<CodeAction> resolve(NbCodeLanguageClient client, CodeAction codeAction, Object data) {
CompletableFuture<CodeAction> future = new CompletableFuture<>();
try {
String uri = ((JsonObject) data).getAsJsonPrimitive(URI).getAsString();
int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
- List<QuickPickItem> constructors = Arrays.asList(gson.fromJson(gson.toJson(((JsonObject) data).get(CONSTRUCTORS)), QuickPickItem[].class));
+ List<QuickPickItem> constructors = Arrays.asList(gson.fromJson(((JsonObject) data).get(CONSTRUCTORS), QuickPickItem[].class));
List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject) data).get(FIELDS), QuickPickItem[].class));
if (constructors.size() < 2 && fields.isEmpty()) {
WorkspaceEdit edit = generate(client, uri, offset, constructors, fields);
@@ -200,39 +209,49 @@ public final class ConstructorGenerator extends CodeActionsProvider {
}
future.complete(codeAction);
} else {
- if (constructors.size() > 1) {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectSuperConstructor(), true, constructors)).thenAccept(selected -> {
- try {
- if (selected != null) {
- selectFields(client, uri, offset, selected, fields).handle((edit, ex) -> {
- if (ex != null) {
- future.completeExceptionally(ex);
- } else {
- if (edit != null) {
- codeAction.setEdit(edit);
- }
- future.complete(codeAction);
- }
- return null;
- });
- } else {
- future.complete(codeAction);
+ LspInputServiceImpl inputService = Lookup.getDefault().lookup(LspInputServiceImpl.class);
+ if (inputService != null) {
+ int totalSteps = constructors.size() > 1 ? 2 : 1;
+ String inputId = inputService.registerInput(params -> {
+ if (params.getStep() < totalSteps) {
+ Either<List<QuickPickItem>, String> constructorData = params.getData().get(CONSTRUCTORS);
+ if (constructorData != null) {
+ List<QuickPickItem> selectedConstructors = constructorData.getLeft();
+ for (QuickPickItem constructor : constructors) {
+ constructor.setPicked(selectedConstructors.contains(constructor));
+ }
}
- } catch (IOException | IllegalArgumentException ex) {
- future.completeExceptionally(ex);
- }
- });
- } else {
- selectFields(client, uri, offset, constructors, fields).handle((edit, ex) -> {
- if (ex != null) {
- future.completeExceptionally(ex);
+ return CompletableFuture.completedFuture(Either.forLeft(new QuickPickStep(totalSteps, CONSTRUCTORS, null, Bundle.DN_SelectSuperConstructor(), true, constructors)));
+ } else if (params.getStep() == totalSteps) {
+ Either<List<QuickPickItem>, String> fieldData = params.getData().get(FIELDS);
+ if (fieldData != null) {
+ List<QuickPickItem> selectedFields = fieldData.getLeft();
+ for (QuickPickItem field : fields) {
+ field.setPicked(selectedFields.contains(field));
+ }
+ }
+ return CompletableFuture.completedFuture(Either.forLeft(new QuickPickStep(totalSteps, FIELDS, null, Bundle.DN_SelectConstructorFields(), true, fields)));
} else {
- if (edit != null) {
- codeAction.setEdit(edit);
+ return CompletableFuture.completedFuture(null);
+ }
+ }, null);
+ client.showMultiStepInput(new ShowMutliStepInputParams(inputId, Bundle.DN_GenerateConstructor())).thenAccept(result -> {
+ inputService.unregisterInput(inputId);
+ Either<List<QuickPickItem>, String> selectedConstructors = result.get(CONSTRUCTORS);
+ Either<List<QuickPickItem>, String> selectedFields = result.get(FIELDS);
+ if (selectedFields != null) {
+ try {
+ WorkspaceEdit edit = generate(client, uri, offset, selectedConstructors != null ? selectedConstructors.getLeft() : constructors, selectedFields.getLeft());
+ if (edit != null) {
+ codeAction.setEdit(edit);
+ }
+ future.complete(codeAction);
+ } catch (IOException | IllegalArgumentException ex) {
+ future.completeExceptionally(ex);
}
+ } else {
future.complete(codeAction);
}
- return null;
});
}
}
@@ -242,29 +261,6 @@ public final class ConstructorGenerator extends CodeActionsProvider {
return future;
}
- @NbBundle.Messages({
- "DN_SelectConstructorFields=Select fields to be initialized by constructor",
- })
- private CompletableFuture<WorkspaceEdit> selectFields(NbCodeLanguageClient client, String uri, int offset, List<QuickPickItem> constructors, List<QuickPickItem> fields) throws IOException, IllegalArgumentException {
- CompletableFuture<WorkspaceEdit> future = new CompletableFuture<>();
- if (!fields.isEmpty()) {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectConstructorFields(), true, fields)).thenAccept(selected -> {
- try {
- if (selected != null) {
- future.complete(generate(client, uri, offset, constructors, selected));
- } else {
- future.complete(null);
- }
- } catch (IOException | IllegalArgumentException ex) {
- future.completeExceptionally(ex);
- }
- });
- } else {
- future.complete(generate(client, uri, offset, constructors, fields));
- }
- return future;
- }
-
@NbBundle.Messages({
"DN_ConstructorAlreadyExists=Given constructor already exists",
})
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java
index 2f96f9f888..1e547a012b 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java
@@ -49,13 +49,20 @@ import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.WorkspaceEdit;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.ElementUtilities;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.InputBoxStep;
+import org.netbeans.modules.java.lsp.server.input.LspInputServiceImpl;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.QuickPickStep;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
@@ -70,6 +77,7 @@ public final class DelegateMethodGenerator extends CodeActionsProvider {
private static final String OFFSET = "offset";
private static final String TYPE = "type";
private static final String FIELDS = "fields";
+ private static final String METHODS = "methods";
private final Gson gson = new Gson();
@@ -118,6 +126,7 @@ public final class DelegateMethodGenerator extends CodeActionsProvider {
if (fields.isEmpty()) {
return Collections.emptyList();
}
+ fields.sort((f1, f2) -> f1.getLabel().compareTo(f2.getLabel()));
String uri = Utils.toUri(info.getFileObject());
QuickPickItem typeItem = new QuickPickItem(createLabel(info, typeElement));
typeItem.setUserData(new ElementData(typeElement));
@@ -132,6 +141,7 @@ public final class DelegateMethodGenerator extends CodeActionsProvider {
@Override
@NbBundle.Messages({
"DN_SelectDelegateMethodField=Select target field to generate delegates for",
+ "DN_SelectDelegateMethods=Select methods to generate delegates for",
})
public CompletableFuture<CodeAction> resolve(NbCodeLanguageClient client, CodeAction codeAction, Object data) {
CompletableFuture<CodeAction> future = new CompletableFuture<>();
@@ -140,99 +150,98 @@ public final class DelegateMethodGenerator extends CodeActionsProvider {
int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
QuickPickItem type = gson.fromJson(gson.toJson(((JsonObject) data).get(TYPE)), QuickPickItem.class);
List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject) data).get(FIELDS), QuickPickItem[].class));
- if (fields.size() == 1) {
- selectMethods(client, uri, offset, type, fields.get(0)).handle((edit, ex) -> {
- if (ex != null) {
- future.completeExceptionally(ex);
- } else {
- if (edit != null) {
- codeAction.setEdit(edit);
+ LspInputServiceImpl inputService = Lookup.getDefault().lookup(LspInputServiceImpl.class);
+ if (inputService != null) {
+ int totalSteps = fields.size() > 1 ? 2 : 1;
+ String inputId = inputService.registerInput(params -> {
+ CompletableFuture<Either<QuickPickStep, InputBoxStep>> f = new CompletableFuture<>();
+ if (params.getStep() < totalSteps) {
+ Either<List<QuickPickItem>, String> fieldData = params.getData().get(FIELDS);
+ if (fieldData != null) {
+ List<QuickPickItem> selectedFields = fieldData.getLeft();
+ for (QuickPickItem field : fields) {
+ field.setPicked(selectedFields.contains(field));
+ }
}
- future.complete(codeAction);
- }
- return null;
- });
- } else {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectDelegateMethodField(), false, fields)).thenAccept(selected -> {
- try {
- if (selected != null && !selected.isEmpty()) {
- selectMethods(client, uri, offset, type, selected.get(0)).handle((edit, ex) -> {
- if (ex != null) {
- future.completeExceptionally(ex);
- } else {
- if (edit != null) {
- codeAction.setEdit(edit);
+ f.complete(Either.forLeft(new QuickPickStep(totalSteps, FIELDS, Bundle.DN_SelectDelegateMethodField(), fields)));
+ } else if (params.getStep() == totalSteps) {
+ Either<List<QuickPickItem>,String> fieldData = params.getData().get(FIELDS);
+ Either<List<QuickPickItem>,String> methodData = params.getData().get(METHODS);
+ QuickPickItem selectedField = (fieldData != null ? fieldData.getLeft() : fields).get(0);
+ List<QuickPickItem> methods = new ArrayList<>();
+ try {
+ FileObject file = Utils.fromUri(uri);
+ JavaSource js = JavaSource.forFileObject(file);
+ if (js == null) {
+ throw new IOException("Cannot get JavaSource for: " + uri);
+ }
+ js.runUserActionTask(info -> {
+ info.toPhase(JavaSource.Phase.RESOLVED);
+ TypeElement origin = (TypeElement) gson.fromJson(gson.toJson(type.getUserData()), ElementData.class).resolve(info);
+ VariableElement field = (VariableElement) gson.fromJson(gson.toJson(selectedField.getUserData()), ElementData.class).resolve(info);
+ if (origin != null && field != null) {
+ final ElementUtilities eu = info.getElementUtilities();
+ final Trees trees = info.getTrees();
+ final Scope scope = info.getTreeUtilities().scopeFor(offset);
+ ElementUtilities.ElementAcceptor acceptor = new ElementUtilities.ElementAcceptor() {
+ @Override
+ public boolean accept(Element e, TypeMirror type) {
+ if (e.getKind() == ElementKind.METHOD && trees.isAccessible(scope, e, (DeclaredType)type)) {
+ Element impl = eu.getImplementationOf((ExecutableElement)e, origin);
+ return impl == null || (!impl.getModifiers().contains(Modifier.FINAL) && impl.getEnclosingElement() != origin);
+ }
+ return false;
+ }
+ };
+ List<QuickPickItem> selectedMethods = methodData != null ? methodData.getLeft() : null;
+ for (ExecutableElement method : ElementFilter.methodsIn(eu.getMembers(field.asType(), acceptor))) {
+ QuickPickItem item = new QuickPickItem(String.format("%s.%s", field.getSimpleName().toString(), createLabel(info, method)));
+ item.setUserData(new ElementData(method));
+ if (selectedMethods != null && selectedMethods.contains(item)) {
+ item.setPicked(true);
+ }
+ methods.add(item);
}
- future.complete(codeAction);
+ } else {
+ throw new IOException("Cannot resolve selected field: " + selectedField.getLabel());
}
- return null;
- });
- } else {
+ }, true);
+ } catch (IOException | IllegalArgumentException ex) {
+ f.completeExceptionally(ex);
+ }
+ methods.sort((m1, m2) -> m1.getLabel().compareTo(m2.getLabel()));
+ f.complete(Either.forLeft(new QuickPickStep(totalSteps, METHODS, null, Bundle.DN_SelectDelegateMethods(), true, methods)));
+ } else {
+ f.complete(null);
+ }
+ return f;
+ }, null);
+ client.showMultiStepInput(new ShowMutliStepInputParams(inputId, Bundle.DN_GenerateDelegateMethod())).thenAccept(result -> {
+ inputService.unregisterInput(inputId);
+ Either<List<QuickPickItem>, String> selectedFields = result.get(FIELDS);
+ QuickPickItem selectedField = (selectedFields != null ? selectedFields.getLeft() : fields).get(0);
+ Either<List<QuickPickItem>, String> selectedMethods = result.get(METHODS);
+ if (selectedField != null && selectedMethods != null) {
+ try {
+ WorkspaceEdit edit = generate(uri, offset, selectedField, selectedMethods.getLeft());
+ if (edit != null) {
+ codeAction.setEdit(edit);
+ }
future.complete(codeAction);
+ } catch (IOException | IllegalArgumentException ex) {
+ future.completeExceptionally(ex);
}
- } catch (IOException | IllegalArgumentException ex) {
- future.completeExceptionally(ex);
+ } else {
+ future.complete(codeAction);
}
});
}
- } catch (JsonSyntaxException | IOException | IllegalArgumentException ex) {
+ } catch (JsonSyntaxException | IllegalArgumentException ex) {
future.completeExceptionally(ex);
}
return future;
}
- @NbBundle.Messages({
- "DN_SelectDelegateMethods=Select methods to generate delegates for",
- })
- private CompletableFuture<WorkspaceEdit> selectMethods(NbCodeLanguageClient client, String uri, int offset, QuickPickItem type, QuickPickItem selectedField) throws IOException, IllegalArgumentException {
- CompletableFuture<WorkspaceEdit> future = new CompletableFuture<>();
- FileObject file = Utils.fromUri(uri);
- JavaSource js = JavaSource.forFileObject(file);
- if (js == null) {
- throw new IOException("Cannot get JavaSource for: " + uri);
- }
- js.runUserActionTask(info -> {
- info.toPhase(JavaSource.Phase.RESOLVED);
- TypeElement origin = (TypeElement) gson.fromJson(gson.toJson(type.getUserData()), ElementData.class).resolve(info);
- VariableElement field = (VariableElement) gson.fromJson(gson.toJson(selectedField.getUserData()), ElementData.class).resolve(info);
- if (origin != null && field != null) {
- final ElementUtilities eu = info.getElementUtilities();
- final Trees trees = info.getTrees();
- final Scope scope = info.getTreeUtilities().scopeFor(offset);
- ElementUtilities.ElementAcceptor acceptor = new ElementUtilities.ElementAcceptor() {
- @Override
- public boolean accept(Element e, TypeMirror type) {
- if (e.getKind() == ElementKind.METHOD && trees.isAccessible(scope, e, (DeclaredType)type)) {
- Element impl = eu.getImplementationOf((ExecutableElement)e, origin);
- return impl == null || (!impl.getModifiers().contains(Modifier.FINAL) && impl.getEnclosingElement() != origin);
- }
- return false;
- }
- };
- List<QuickPickItem> methods = new ArrayList<>();
- for (ExecutableElement method : ElementFilter.methodsIn(eu.getMembers(field.asType(), acceptor))) {
- QuickPickItem item = new QuickPickItem(String.format("%s.%s", field.getSimpleName().toString(), createLabel(info, method)));
- item.setUserData(new ElementData(method));
- methods.add(item);
- }
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectDelegateMethods(), true, methods)).thenAccept(selected -> {
- try {
- if (selected != null && !selected.isEmpty()) {
- future.complete(generate(uri, offset, selectedField, selected));
- } else {
- future.complete(null);
- }
- } catch (IOException | IllegalArgumentException ex) {
- future.completeExceptionally(ex);
- }
- });
- } else {
- future.complete(null);
- }
- }, true);
- return future;
- }
-
private WorkspaceEdit generate(String uri, int offset, QuickPickItem selectedField, List<QuickPickItem> selectedMethods) throws IOException, IllegalArgumentException {
FileObject file = Utils.fromUri(uri);
JavaSource js = JavaSource.forFileObject(file);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/EqualsHashCodeGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/EqualsHashCodeGenerator.java
index 4c102270e5..8f4968a8d4 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/EqualsHashCodeGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/EqualsHashCodeGenerator.java
@@ -46,6 +46,8 @@ import org.eclipse.lsp4j.WorkspaceEdit;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;
@@ -131,15 +133,16 @@ public final class EqualsHashCodeGenerator extends CodeActionsProvider {
String uri = ((JsonObject) data).getAsJsonPrimitive(URI).getAsString();
int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject) data).get(FIELDS), QuickPickItem[].class));
+ String title;
String text;
boolean generateEquals = HASH_CODE_ONLY != kind;
boolean generateHashCode = EQUALS_ONLY != kind;
switch (kind) {
- case EQUALS_ONLY: text = Bundle.DN_SelectEquals(); break;
- case HASH_CODE_ONLY: text = Bundle.DN_SelectHashCode(); break;
- default: text = Bundle.DN_SelectEqualsHashCode(); break;
+ case EQUALS_ONLY: title = Bundle.DN_GenerateEquals(); text = Bundle.DN_SelectEquals(); break;
+ case HASH_CODE_ONLY: title = Bundle.DN_GenerateHashCode(); text = Bundle.DN_SelectHashCode(); break;
+ default: title = Bundle.DN_GenerateEqualsHashCode(); text = Bundle.DN_SelectEqualsHashCode(); break;
}
- client.showQuickPick(new ShowQuickPickParams(text, true, fields)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(title, text, true, fields)).thenAccept(selected -> {
try {
if (selected != null) {
FileObject file = Utils.fromUri(uri);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java
index 5716a69499..1dbd16a6db 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java
@@ -54,6 +54,8 @@ import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.modules.java.editor.codegen.GeneratorUtils;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;
@@ -140,14 +142,15 @@ public final class GetterSetterGenerator extends CodeActionsProvider {
int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
boolean all = ((JsonObject) data).getAsJsonPrimitive(ALL).getAsBoolean();
List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject) data).get(FIELDS), QuickPickItem[].class));
+ String title;
String text;
switch (kind) {
- case GeneratorUtils.GETTERS_ONLY: text = Bundle.DN_SelectGetters(); break;
- case GeneratorUtils.SETTERS_ONLY: text = Bundle.DN_SelectSetters(); break;
- default: text = Bundle.DN_SelectGettersSetters(); break;
+ case GeneratorUtils.GETTERS_ONLY: title = Bundle.DN_GenerateGetters(); text = Bundle.DN_SelectGetters(); break;
+ case GeneratorUtils.SETTERS_ONLY: title = Bundle.DN_GenerateSetters(); text = Bundle.DN_SelectSetters(); break;
+ default: title = Bundle.DN_GenerateGettersSetters(); text = Bundle.DN_SelectGettersSetters(); break;
}
if (all && fields.size() > 1) {
- client.showQuickPick(new ShowQuickPickParams(text, true, fields)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(title, text, true, fields)).thenAccept(selected -> {
try {
if (selected != null && !selected.isEmpty()) {
WorkspaceEdit edit = generate(kind, uri, offset, selected);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ImplementOverrideMethodGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ImplementOverrideMethodGenerator.java
index 5a3c72418f..ef04a84e85 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ImplementOverrideMethodGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ImplementOverrideMethodGenerator.java
@@ -40,7 +40,6 @@ import javax.lang.model.element.TypeElement;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionParams;
-import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.netbeans.api.java.source.CompilationController;
@@ -49,6 +48,8 @@ import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.modules.java.editor.codegen.GeneratorUtils;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;
@@ -140,8 +141,9 @@ public final class ImplementOverrideMethodGenerator extends CodeActionsProvider
int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
boolean isImplement = ((JsonObject) data).getAsJsonPrimitive(IS_IMPLEMET).getAsBoolean();
List<QuickPickItem> methods = Arrays.asList(gson.fromJson(((JsonObject) data).get(METHODS), QuickPickItem[].class));
+ String title = isImplement ? Bundle.DN_GenerateImplementMethod(): Bundle.DN_GenerateOverrideMethod();
String text = isImplement ? Bundle.DN_SelectImplementMethod() : Bundle.DN_SelectOverrideMethod();
- client.showQuickPick(new ShowQuickPickParams(text, true, methods)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(title, text, true, methods)).thenAccept(selected -> {
try {
if (selected != null && !selected.isEmpty()) {
WorkspaceEdit edit = generate(uri, offset, isImplement, selected);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java
index bc235807d7..83b130c3e9 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java
@@ -49,6 +49,7 @@ import org.netbeans.api.java.source.GeneratorUtilities;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
import org.openide.util.BaseUtilities;
@@ -117,7 +118,7 @@ public final class LoggerGenerator extends CodeActionsProvider {
try {
String uri = ((JsonObject) data).getAsJsonPrimitive(URI).getAsString();
int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
- client.showInputBox(new ShowInputBoxParams(Bundle.DN_SelectLoggerName(), "LOG")).thenAccept(value -> {
+ client.showInputBox(new ShowInputBoxParams(Bundle.DN_GenerateLogger(), Bundle.DN_SelectLoggerName(), "LOG", false)).thenAccept(value -> {
try {
if (value != null && BaseUtilities.isJavaIdentifier(value)) {
FileObject file = Utils.fromUri(uri);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
index b0845195b4..65710539c0 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
@@ -50,6 +50,9 @@ import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.SourceGroupModifier;
import org.netbeans.api.templates.CreateDescriptor;
import org.netbeans.api.templates.FileBuilder;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
@@ -243,7 +246,7 @@ final class LspTemplateUI {
private static CompletionStage<DataObject> findTemplate(DataFolder templates, NbCodeLanguageClient client) {
final List<QuickPickItem> categories = quickPickTemplates(templates);
- final CompletionStage<List<QuickPickItem>> pickGroup = client.showQuickPick(new ShowQuickPickParams(Bundle.CTL_TemplateUI_SelectGroup(), false, categories));
+ final CompletionStage<List<QuickPickItem>> pickGroup = client.showQuickPick(new ShowQuickPickParams(Bundle.CTL_TemplateUI_SelectGroup(), categories));
final CompletionStage<DataFolder> group = pickGroup.thenApply((selectedGroups) -> {
final String chosen = singleSelection(selectedGroups);
FileObject chosenFo = templates.getPrimaryFile().getFileObject(chosen);
@@ -251,7 +254,7 @@ final class LspTemplateUI {
});
final CompletionStage<List<QuickPickItem>> pickProject = group.thenCompose(chosenGroup -> {
List<QuickPickItem> projectTypes = quickPickTemplates(chosenGroup);
- return client.showQuickPick(new ShowQuickPickParams(Bundle.CTL_TemplateUI_SelectTemplate(), false, projectTypes));
+ return client.showQuickPick(new ShowQuickPickParams(Bundle.CTL_TemplateUI_SelectTemplate(), projectTypes));
});
final CompletionStage<DataObject> findTemplate = pickProject.thenCombine(group, (selectedTemplates, chosenGroup) -> {
try {
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
index 73c0d8d6a0..1c9b2b11c6 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
@@ -18,8 +18,8 @@
*/
package org.netbeans.modules.java.lsp.server.protocol;
-import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
import org.eclipse.lsp4j.ApplyWorkspaceEditResponse;
@@ -36,6 +36,12 @@ import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.eclipse.lsp4j.UnregistrationParams;
import org.eclipse.lsp4j.WorkDoneProgressCreateParams;
import org.eclipse.lsp4j.WorkspaceFolder;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
/**
* Convenience wrapper that binds language client's remote proxy together with
@@ -83,6 +89,11 @@ class NbCodeClientWrapper implements NbCodeLanguageClient {
return remote.showInputBox(params);
}
+ @Override
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ return remote.showMultiStepInput(params);
+ }
+
@Override
public void notifyTestProgress(TestProgressParams params) {
remote.notifyTestProgress(params);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
index 09c6adf5c0..aac9970f41 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
@@ -18,14 +18,20 @@
*/
package org.netbeans.modules.java.lsp.server.protocol;
-import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.MessageParams;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.services.LanguageClient;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
/**
* An extension to the standard LanguageClient that adds several messages missing
@@ -69,6 +75,15 @@ public interface NbCodeLanguageClient extends LanguageClient {
@JsonRequest("window/showInputBox")
public CompletableFuture<String> showInputBox(@NonNull ShowInputBoxParams params);
+ /**
+ * Shows a mutli-step input using QuickPicks and InputBoxes.
+ *
+ * @param params input parameters
+ * @return collected input values and selected items
+ */
+ @JsonRequest("window/showMultiStepInput")
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(@NonNull ShowMutliStepInputParams params);
+
/**
* Notifies client of running tests progress. Provides information about a test suite being loaded,
* started, completed or skipped during a test run.
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java
index 539c261d75..9c20f0a13b 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbLanguageServer.java
@@ -21,6 +21,7 @@ package org.netbeans.modules.java.lsp.server.protocol;
import org.eclipse.lsp4j.jsonrpc.services.JsonDelegate;
import org.eclipse.lsp4j.services.LanguageServer;
import org.netbeans.modules.java.lsp.server.explorer.api.TreeViewService;
+import org.netbeans.modules.java.lsp.server.input.InputService;
/**
*
@@ -29,4 +30,6 @@ import org.netbeans.modules.java.lsp.server.explorer.api.TreeViewService;
public interface NbLanguageServer extends LanguageServer {
@JsonDelegate
public TreeViewService getTreeViewService();
+ @JsonDelegate
+ public InputService getInputService();
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
index dbe1d65502..2bda39c22c 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
@@ -77,6 +77,7 @@ import org.eclipse.lsp4j.jsonrpc.JsonRpcException;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.MessageIssueException;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage;
import org.eclipse.lsp4j.jsonrpc.messages.RequestMessage;
@@ -105,6 +106,12 @@ import org.netbeans.modules.java.lsp.server.explorer.LspTreeViewServiceImpl;
import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
import org.netbeans.modules.java.lsp.server.explorer.api.TreeViewService;
import org.netbeans.modules.java.lsp.server.files.OpenedDocuments;
+import org.netbeans.modules.java.lsp.server.input.InputService;
+import org.netbeans.modules.java.lsp.server.input.LspInputServiceImpl;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.java.lsp.server.progress.OperationContext;
import org.netbeans.modules.progress.spi.InternalHandle;
import org.netbeans.spi.project.ActionProgress;
@@ -325,6 +332,7 @@ public final class Server {
);
private final LspTreeViewServiceImpl treeService = new LspTreeViewServiceImpl(sessionLookup);
+ private final LspInputServiceImpl inputService = new LspInputServiceImpl();
/**
* Projects that are or were opened. After projects open, their CompletableFutures
@@ -849,6 +857,11 @@ public final class Server {
return treeService;
}
+ @JsonDelegate
+ public InputService getInputService() {
+ return inputService;
+ }
+
@Override
public TextDocumentService getTextDocumentService() {
return textDocumentService;
@@ -877,6 +890,7 @@ public final class Server {
});
sessionServices.add(new WorkspaceUIContext(client));
sessionServices.add(treeService.getNodeRegistry());
+ sessionServices.add(inputService);
((LanguageClientAware) getTextDocumentService()).connect(client);
((LanguageClientAware) getWorkspaceService()).connect(client);
((LanguageClientAware) treeService).connect(client);
@@ -956,6 +970,12 @@ public final class Server {
return CompletableFuture.completedFuture(params.getValue());
}
+ @Override
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ logWarning(params);
+ return CompletableFuture.completedFuture(null);
+ }
+
@Override
public void notifyTestProgress(TestProgressParams params) {
logWarning(params);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java
index 5424309a26..c7bff0f383 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SurroundWithHint.java
@@ -39,7 +39,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -68,6 +67,7 @@ import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateFilter;
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateParameter;
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java
index 72d9e7e3dd..af2901473e 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java
@@ -48,6 +48,8 @@ import org.netbeans.api.java.source.GeneratorUtilities;
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;
@@ -132,7 +134,7 @@ public final class ToStringGenerator extends CodeActionsProvider {
}
future.complete(codeAction);
} else {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectToString(), true, fields)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(Bundle.DN_GenerateToString(), Bundle.DN_SelectToString(), true, fields)).thenAccept(selected -> {
try {
if (selected != null) {
WorkspaceEdit edit = generate(uri, offset, fields);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceUIContext.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceUIContext.java
index ce29976ae5..4e96306a73 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceUIContext.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceUIContext.java
@@ -23,6 +23,9 @@ import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.MessageActionItem;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.ShowMessageRequestParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.java.lsp.server.ui.UIContext;
import org.openide.awt.StatusDisplayer;
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoring.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoring.java
index 2250f7061b..6abdf61bab 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoring.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ChangeMethodParametersRefactoring.java
@@ -57,9 +57,9 @@ import org.netbeans.api.java.source.TreePathHandle;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.editor.java.Utilities;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
import org.netbeans.modules.java.lsp.server.protocol.CodeActionsProvider;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.refactoring.java.api.ChangeParametersRefactoring;
import org.netbeans.modules.refactoring.java.api.JavaRefactoringUtils;
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ExtractSuperclassOrInterfaceRefactoring.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ExtractSuperclassOrInterfaceRefactoring.java
index ff53dc5c15..9db08e12fc 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ExtractSuperclassOrInterfaceRefactoring.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/ExtractSuperclassOrInterfaceRefactoring.java
@@ -56,11 +56,11 @@ import org.netbeans.api.java.source.TreePathHandle;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.CodeActionsProvider;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.refactoring.api.AbstractRefactoring;
import org.netbeans.modules.refactoring.java.api.ExtractInterfaceRefactoring;
@@ -183,7 +183,7 @@ public final class ExtractSuperclassOrInterfaceRefactoring extends CodeRefactori
String uri = gson.fromJson(gson.toJson(arguments.get(0)), String.class);
QuickPickItem type = gson.fromJson(gson.toJson(arguments.get(1)), QuickPickItem.class);
List<QuickPickItem> members = Arrays.asList(gson.fromJson(gson.toJson(arguments.get(2)), QuickPickItem[].class));
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectMembersToExtract(), true, members)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(null, Bundle.DN_SelectMembersToExtract(), true, members)).thenAccept(selected -> {
if (selected != null && !selected.isEmpty()) {
String label = EXTRACT_SUPERCLASS_REFACTORING_COMMAND.equals(command) ? Bundle.DN_SelectClassName() : Bundle.DN_SelectInterfaceName();
String value = EXTRACT_SUPERCLASS_REFACTORING_COMMAND.equals(command) ? "NewClass" : "NewInterface";
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PullUpRefactoring.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PullUpRefactoring.java
index 4f8af76ea5..a53afcf719 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PullUpRefactoring.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PullUpRefactoring.java
@@ -57,10 +57,10 @@ import org.netbeans.api.java.source.TreePathHandle;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.CodeActionsProvider;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.refactoring.java.api.JavaRefactoringUtils;
import org.netbeans.modules.refactoring.java.api.MemberInfo;
@@ -147,12 +147,12 @@ public final class PullUpRefactoring extends CodeRefactoring {
QuickPickItem sourceItem = gson.fromJson(gson.toJson(arguments.get(2)), QuickPickItem.class);
List<QuickPickItem> superclasses = Arrays.asList(gson.fromJson(gson.toJson(arguments.get(3)), QuickPickItem[].class));
if (superclasses.size() > 1) {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectTargetSupertype(), false, superclasses)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectTargetSupertype(), superclasses)).thenAccept(selected -> {
if (selected != null && !selected.isEmpty()) {
QuickPickItem targetItem = selected.get(0);
List<QuickPickItem> members = getMembers(client, uri, offset, sourceItem, targetItem);
if (!members.isEmpty()) {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectMembersToPullUp(), true, members)).thenAccept(selectedMembers -> {
+ client.showQuickPick(new ShowQuickPickParams(null, Bundle.DN_SelectMembersToPullUp(), true, members)).thenAccept(selectedMembers -> {
if (selectedMembers != null && !selectedMembers.isEmpty()) {
pullUp(client, uri, sourceItem, targetItem, selectedMembers);
}
@@ -164,7 +164,7 @@ public final class PullUpRefactoring extends CodeRefactoring {
QuickPickItem targetItem = superclasses.get(0);
List<QuickPickItem> members = getMembers(client, uri, offset, sourceItem, targetItem);
if (!members.isEmpty()) {
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectMembersToPullUp(), true, members)).thenAccept(selectedMembers -> {
+ client.showQuickPick(new ShowQuickPickParams(null, Bundle.DN_SelectMembersToPullUp(), true, members)).thenAccept(selectedMembers -> {
if (selectedMembers != null && !selectedMembers.isEmpty()) {
pullUp(client, uri, sourceItem, targetItem, selectedMembers);
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PushDownRefactoring.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PushDownRefactoring.java
index 2c839e97cf..6acfa1537e 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PushDownRefactoring.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/refactoring/PushDownRefactoring.java
@@ -53,10 +53,10 @@ import org.netbeans.api.java.source.TreePathHandle;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.java.lsp.server.Utils;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.CodeActionsProvider;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.refactoring.java.api.JavaRefactoringUtils;
import org.netbeans.modules.refactoring.java.api.MemberInfo;
@@ -155,7 +155,7 @@ public final class PushDownRefactoring extends CodeRefactoring {
String uri = gson.fromJson(gson.toJson(arguments.get(0)), String.class);
QuickPickItem sourceItem = gson.fromJson(gson.toJson(arguments.get(1)), QuickPickItem.class);
List<QuickPickItem> members = Arrays.asList(gson.fromJson(gson.toJson(arguments.get(2)), QuickPickItem[].class));
- client.showQuickPick(new ShowQuickPickParams(Bundle.DN_SelectMembersToPushDown(), true, members)).thenAccept(selected -> {
+ client.showQuickPick(new ShowQuickPickParams(null, Bundle.DN_SelectMembersToPushDown(), true, members)).thenAccept(selected -> {
if (selected != null && !selected.isEmpty()) {
pushDown(client, uri, sourceItem, selected);
}
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/NotifyDescriptorAdapter.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/NotifyDescriptorAdapter.java
index b8d05fc20a..66ea4bff5a 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/NotifyDescriptorAdapter.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/NotifyDescriptorAdapter.java
@@ -44,9 +44,9 @@ import javax.swing.JButton;
import org.eclipse.lsp4j.MessageActionItem;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.ShowMessageRequestParams;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.openide.NotifyDescriptor;
import org.openide.awt.Actions;
import org.openide.util.NbBundle;
@@ -346,7 +346,7 @@ class NotifyDescriptorAdapter {
for (NotifyDescriptor.QuickPick.Item item : qp.getItems()) {
items.put(new QuickPickItem(item.getLabel(), item.getDescription(), null, item.isSelected(), null), item);
}
- ShowQuickPickParams params = new ShowQuickPickParams(qp.getTitle(), qp.isMultipleSelection(), new ArrayList<>(items.keySet()));
+ ShowQuickPickParams params = new ShowQuickPickParams(null, qp.getTitle(), qp.isMultipleSelection(), new ArrayList<>(items.keySet()));
CompletableFuture<List<QuickPickItem>> qpF = client.showQuickPick(params);
Ctrl<T> ctrl = new Ctrl<>(qpF);
qpF.thenAccept(selected -> {
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/UIContext.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/UIContext.java
index 0fa9bd7b03..56c8cdedb3 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/UIContext.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/UIContext.java
@@ -29,9 +29,9 @@ import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.modules.java.lsp.server.protocol.HtmlPageParams;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
import org.openide.awt.StatusDisplayer.Message;
import org.openide.util.Lookup;
diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
index abfa6eb53a..1ac6dfe66d 100644
--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
@@ -20,6 +20,7 @@ package org.netbeans.modules.java.lsp.server;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
@@ -31,15 +32,17 @@ import org.eclipse.lsp4j.ProgressParams;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.eclipse.lsp4j.WorkDoneProgressCreateParams;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
import org.netbeans.modules.java.lsp.server.protocol.DecorationRenderOptions;
import org.netbeans.modules.java.lsp.server.protocol.HtmlPageParams;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeClientCapabilities;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
import org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams;
@@ -85,6 +88,11 @@ public abstract class TestCodeLanguageClient implements NbCodeLanguageClient {
throw new UnsupportedOperationException();
}
+ @Override
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public void notifyTestProgress(TestProgressParams params) {
throw new UnsupportedOperationException();
diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
index 5dc3a03f35..391fba10d9 100644
--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
@@ -31,6 +31,7 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -54,6 +55,7 @@ import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.WorkDoneProgressCreateParams;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
+import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.launch.LSPLauncher;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
@@ -70,10 +72,11 @@ import org.netbeans.modules.java.lsp.server.protocol.HtmlPageParams;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeClientCapabilities;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
import org.netbeans.modules.java.lsp.server.protocol.NbLanguageServer;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams;
@@ -194,6 +197,11 @@ public class ProjectViewTest extends NbTestCase {
return CompletableFuture.completedFuture(null);
}
+ @Override
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ return CompletableFuture.completedFuture(null);
+ }
+
@Override
public void notifyTestProgress(TestProgressParams params) {
}
diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
index a68bcbb287..03ae5c11e0 100644
--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
@@ -42,10 +42,10 @@ import org.netbeans.modules.java.lsp.server.TestCodeLanguageClient;
import org.netbeans.modules.java.lsp.server.protocol.DecorationRenderOptions;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeClientCapabilities;
import org.netbeans.modules.java.lsp.server.explorer.api.NodeChangedParams;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
import org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
import org.netbeans.modules.java.lsp.server.protocol.TestSuiteInfo;
diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java
index 33b37492d1..2ffcf67ce2 100644
--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java
+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java
@@ -53,8 +53,10 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Collectors;
+import javax.lang.model.element.ElementKind;
import javax.swing.Icon;
import javax.swing.event.ChangeListener;
import javax.swing.text.Document;
@@ -159,11 +161,16 @@ import org.netbeans.api.sendopts.CommandLine;
import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.java.hints.infrastructure.JavaErrorProvider;
import org.netbeans.modules.java.lsp.server.TestCodeLanguageClient;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.java.lsp.server.refactoring.ChangeMethodParameterUI;
import org.netbeans.modules.java.lsp.server.refactoring.MoveElementUI;
import org.netbeans.modules.java.lsp.server.refactoring.ParameterUI;
import org.netbeans.modules.java.lsp.server.ui.MockHtmlViewer;
import org.netbeans.modules.java.source.BootClassPathUtil;
+import org.netbeans.modules.java.source.ElementHandleAccessor;
import org.netbeans.modules.java.source.parsing.JavacParser;
import org.netbeans.modules.parsing.api.ResultIterator;
import org.netbeans.modules.parsing.impl.indexing.implspi.CacheFolderProvider;
@@ -1846,7 +1853,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 17), new Position(2, 17)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 3);
Optional<CodeAction> generateVariable =
codeActions.stream()
.filter(Either::isRight)
@@ -2148,7 +2154,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(0, 15), new Position(0, 15)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 2);
Optional<CodeAction> implementAllAbstractMethods =
codeActions.stream()
.filter(Either::isRight)
@@ -2239,7 +2244,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 35), new Position(2, 35)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 1);
Optional<CodeAction> implementAllAbstractMethods =
codeActions.stream()
.filter(Either::isRight)
@@ -2327,7 +2331,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(1, 5), new Position(1, 5)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 2);
Optional<CodeAction> implementAllAbstractMethods =
codeActions.stream()
.filter(Either::isRight)
@@ -2416,7 +2419,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 8), new Position(2, 18)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 4);
Optional<CodeAction> introduceVariable =
codeActions.stream()
.filter(Either::isRight)
@@ -2526,7 +2528,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 8), new Position(2, 18)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 4);
Optional<CodeAction> introduceConstant =
codeActions.stream()
.filter(Either::isRight)
@@ -2631,7 +2632,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 8), new Position(2, 18)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 4);
Optional<CodeAction> introduceField =
codeActions.stream()
.filter(Either::isRight)
@@ -2736,7 +2736,6 @@ public class ServerTest extends NbTestCase {
}
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 8), new Position(2, 18)), new CodeActionContext(diags[0]))).get();
- assertTrue(codeActions.size() >= 4);
Optional<CodeAction> introduceMethod =
codeActions.stream()
.filter(Either::isRight)
@@ -2832,7 +2831,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 6), new Position(2, 6)), new CodeActionContext(Arrays.asList()))).get();
- assertEquals(4, codeActions.size());
Optional<CodeAction> generateGetterSetter =
codeActions.stream()
.filter(Either::isRight)
@@ -2872,6 +2870,7 @@ public class ServerTest extends NbTestCase {
try (Writer w = new FileWriter(src)) {
w.write(code);
}
+ AtomicReference<Object> data = new AtomicReference<>();
Launcher<LanguageServer> serverLauncher = LSPLauncher.createClientLauncher(new TestCodeLanguageClient() {
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
@@ -2879,8 +2878,11 @@ public class ServerTest extends NbTestCase {
}
@Override
- public CompletableFuture<List<QuickPickItem>> showQuickPick(ShowQuickPickParams params) {
- return CompletableFuture.completedFuture(params.getItems().stream().filter(item -> item.isPicked()).collect(Collectors.toList()));
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ Map<String, Either<List<QuickPickItem>, String>> map = new HashMap<>();
+ List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject)data.get()).getAsJsonObject("data").get("fields"), QuickPickItem[].class));
+ map.put("fields", Either.forLeft(fields.stream().filter(item -> item.isPicked()).collect(Collectors.toList())));
+ return CompletableFuture.completedFuture(map);
}
}, client.getInputStream(), client.getOutputStream());
serverLauncher.startListening();
@@ -2890,7 +2892,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(1, 6), new Position(1, 6)), new CodeActionContext(Arrays.asList()))).get();
- assertEquals(2, codeActions.size());
Optional<CodeAction> generateConstructor =
codeActions.stream()
.filter(Either::isRight)
@@ -2898,6 +2899,7 @@ public class ServerTest extends NbTestCase {
.filter(a -> Bundle.DN_GenerateConstructor().equals(a.getTitle()))
.findAny();
assertTrue(generateConstructor.isPresent());
+ data.set(generateConstructor.get().getData());
CodeAction resolvedCodeAction = server.getTextDocumentService().resolveCodeAction(generateConstructor.get()).get();
assertNotNull(resolvedCodeAction);
WorkspaceEdit edit = resolvedCodeAction.getEdit();
@@ -2963,7 +2965,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(3, 0), new Position(3, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(10, codeActions.size());
Optional<CodeAction> generateGetterSetter =
codeActions.stream()
.filter(Either::isRight)
@@ -2993,7 +2994,6 @@ public class ServerTest extends NbTestCase {
fileChanges.get(0).getNewText());
server.getTextDocumentService().didChange(new DidChangeTextDocumentParams(id, Arrays.asList(new TextDocumentContentChangeEvent(fileChanges.get(0).getRange(), 0, fileChanges.get(0).getNewText()))));
codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(3, 0), new Position(3, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> generateGetter =
codeActions.stream()
.filter(Either::isRight)
@@ -3028,6 +3028,7 @@ public class ServerTest extends NbTestCase {
try (Writer w = new FileWriter(src)) {
w.write(code);
}
+ AtomicReference<Object> data = new AtomicReference<>();
Launcher<LanguageServer> serverLauncher = LSPLauncher.createClientLauncher(new TestCodeLanguageClient() {
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
@@ -3035,10 +3036,14 @@ public class ServerTest extends NbTestCase {
}
@Override
- public CompletableFuture<List<QuickPickItem>> showQuickPick(ShowQuickPickParams params) {
- return CompletableFuture.completedFuture(params.getItems().size() > 2 ? params.getItems().subList(0, 2) : params.getItems());
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ Map<String, Either<List<QuickPickItem>, String>> map = new HashMap<>();
+ List<QuickPickItem> constructors = Arrays.asList(gson.fromJson(((JsonObject)data.get()).getAsJsonObject("data").get("constructors"), QuickPickItem[].class));
+ map.put("constructors", Either.forLeft(constructors.subList(0, 2)));
+ List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject)data.get()).getAsJsonObject("data").get("fields"), QuickPickItem[].class));
+ map.put("fields", Either.forLeft(fields));
+ return CompletableFuture.completedFuture(map);
}
-
}, client.getInputStream(), client.getOutputStream());
serverLauncher.startListening();
LanguageServer server = serverLauncher.getRemoteProxy();
@@ -3047,7 +3052,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 0), new Position(2, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> generateConstructor =
codeActions.stream()
.filter(Either::isRight)
@@ -3055,6 +3059,7 @@ public class ServerTest extends NbTestCase {
.filter(a -> Bundle.DN_GenerateConstructor().equals(a.getTitle()))
.findAny();
assertTrue(generateConstructor.isPresent());
+ data.set(generateConstructor.get().getData());
CodeAction resolvedCodeAction = server.getTextDocumentService().resolveCodeAction(generateConstructor.get()).get();
assertNotNull(resolvedCodeAction);
WorkspaceEdit edit = resolvedCodeAction.getEdit();
@@ -3112,7 +3117,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(5, 0), new Position(5, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(10, codeActions.size());
Optional<CodeAction> generateEquals =
codeActions.stream()
.filter(Either::isRight)
@@ -3180,7 +3184,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 0), new Position(2, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> generateToString =
codeActions.stream()
.filter(Either::isRight)
@@ -3220,6 +3223,7 @@ public class ServerTest extends NbTestCase {
try (Writer w = new FileWriter(src)) {
w.write(code);
}
+ AtomicReference<Object> data = new AtomicReference<>();
Launcher<LanguageServer> serverLauncher = LSPLauncher.createClientLauncher(new TestCodeLanguageClient() {
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
@@ -3231,6 +3235,24 @@ public class ServerTest extends NbTestCase {
return CompletableFuture.completedFuture(params.getItems().size() > 2 ? params.getItems().subList(0, 2) : params.getItems());
}
+ @Override
+ public CompletableFuture<Map<String, Either<List<QuickPickItem>, String>>> showMultiStepInput(ShowMutliStepInputParams params) {
+ Map<String, Either<List<QuickPickItem>, String>> map = new HashMap<>();
+ List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject)data.get()).getAsJsonObject("data").get("fields"), QuickPickItem[].class));
+ map.put("methods", Either.forLeft(Arrays.asList(new QuickPickItem[] {
+ new QuickPickItem("s.chars(): IntStream", null, null, false, new CodeActionsProvider.ElementData(ElementHandleAccessor.getInstance().create(ElementKind.METHOD, new String[] {
+ "java.lang.CharSequence",
+ "chars",
+ "()Ljava/util/stream/IntStream;"
+ }))),
+ new QuickPickItem("s.codePoints(): IntStream", null, null, false, new CodeActionsProvider.ElementData(ElementHandleAccessor.getInstance().create(ElementKind.METHOD, new String[] {
+ "java.lang.CharSequence",
+ "codePoints",
+ "()Ljava/util/stream/IntStream;"
+ })))
+ })));
+ return CompletableFuture.completedFuture(map);
+ }
}, client.getInputStream(), client.getOutputStream());
serverLauncher.startListening();
LanguageServer server = serverLauncher.getRemoteProxy();
@@ -3239,7 +3261,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 0), new Position(2, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> generateDelegateMethod =
codeActions.stream()
.filter(Either::isRight)
@@ -3247,6 +3268,7 @@ public class ServerTest extends NbTestCase {
.filter(a -> Bundle.DN_GenerateDelegateMethod().equals(a.getTitle()))
.findAny();
assertTrue(generateDelegateMethod.isPresent());
+ data.set(generateDelegateMethod.get().getData());
CodeAction resolvedCodeAction = server.getTextDocumentService().resolveCodeAction(generateDelegateMethod.get()).get();
assertNotNull(resolvedCodeAction);
WorkspaceEdit edit = resolvedCodeAction.getEdit();
@@ -3302,7 +3324,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 0), new Position(2, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> generateOverrideMethod =
codeActions.stream()
.filter(Either::isRight)
@@ -3367,7 +3388,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(2, 0), new Position(2, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> generateLogger =
codeActions.stream()
.filter(Either::isRight)
@@ -3446,7 +3466,6 @@ public class ServerTest extends NbTestCase {
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code)));
VersionedTextDocumentIdentifier id = new VersionedTextDocumentIdentifier(src.toURI().toString(), 1);
List<Either<Command, CodeAction>> codeActions = server.getTextDocumentService().codeAction(new CodeActionParams(id, new Range(new Position(6, 0), new Position(6, 0)), new CodeActionContext(Arrays.asList(), Arrays.asList(CodeActionKind.Source)))).get();
- assertEquals(8, codeActions.size());
Optional<CodeAction> organizeImports =
codeActions.stream()
.filter(Either::isRight)
diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ui/AbstractDialogDisplayerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ui/AbstractDialogDisplayerTest.java
index 291165c0a0..9f12310272 100644
--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ui/AbstractDialogDisplayerTest.java
+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ui/AbstractDialogDisplayerTest.java
@@ -37,9 +37,9 @@ import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.netbeans.junit.NbTestCase;
-import org.netbeans.modules.java.lsp.server.protocol.QuickPickItem;
-import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams;
-import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.input.QuickPickItem;
+import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
+import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
import org.openide.NotifyDescriptor;
import org.openide.awt.StatusDisplayer;
diff --git a/java/java.lsp.server/vscode/src/extension.ts b/java/java.lsp.server/vscode/src/extension.ts
index 762537d5ce..05cb35115c 100644
--- a/java/java.lsp.server/vscode/src/extension.ts
+++ b/java/java.lsp.server/vscode/src/extension.ts
@@ -46,17 +46,15 @@ import { ChildProcess } from 'child_process';
import * as vscode from 'vscode';
import * as launcher from './nbcode';
import {NbTestAdapter} from './testAdapter';
-import { asRanges, StatusMessageRequest, ShowStatusMessageParams, QuickPickRequest, InputBoxRequest, TestProgressNotification, DebugConnector,
+import { asRanges, StatusMessageRequest, ShowStatusMessageParams, QuickPickRequest, InputBoxRequest, MutliStepInputRequest, TestProgressNotification, DebugConnector,
TextEditorDecorationCreateRequest, TextEditorDecorationSetNotification, TextEditorDecorationDisposeNotification, HtmlPageRequest, HtmlPageParams,
- SetTextEditorDecorationParams,
- ProjectActionParams,
- UpdateConfigurationRequest,
- UpdateConfigParams
+ SetTextEditorDecorationParams, ProjectActionParams, UpdateConfigurationRequest, QuickPickStep, InputBoxStep
} from './protocol';
import * as launchConfigurations from './launchConfigurations';
import { createTreeViewService, TreeViewService, TreeItemDecorator, Visualizer, CustomizableTreeDataProvider } from './explorer';
import { initializeRunConfiguration, runConfigurationProvider, runConfigurationNodeProvider, configureRunSettings, runConfigurationUpdateAll } from './runConfiguration';
import { TLSSocket } from 'tls';
+import { InputStep, MultiStepInput } from './utils';
const API_VERSION : string = "1.0";
const DATABASE: string = 'Database';
@@ -829,7 +827,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
c.onRequest(HtmlPageRequest.type, showHtmlPage);
c.onNotification(LogMessageNotification.type, (param) => handleLog(log, param.message));
c.onRequest(QuickPickRequest.type, async param => {
- const selected = await window.showQuickPick(param.items, { placeHolder: param.placeHolder, canPickMany: param.canPickMany });
+ const selected = await window.showQuickPick(param.items, { title: param.title, placeHolder: param.placeHolder, canPickMany: param.canPickMany });
return selected ? Array.isArray(selected) ? selected : [selected] : undefined;
});
c.onRequest(UpdateConfigurationRequest.type, async (param) => {
@@ -837,7 +835,44 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
runConfigurationUpdateAll();
});
c.onRequest(InputBoxRequest.type, async param => {
- return await window.showInputBox({ prompt: param.prompt, value: param.value, password: param.password });
+ return await window.showInputBox({ title: param.title, prompt: param.prompt, value: param.value, password: param.password });
+ });
+ c.onRequest(MutliStepInputRequest.type, async param => {
+ const data: { [name: string]: readonly vscode.QuickPickItem[] | string } = {};
+ async function nextStep(input: MultiStepInput, step: number, state: { [name: string]: readonly vscode.QuickPickItem[] | string }): Promise<InputStep | void> {
+ const inputStep = await c.sendRequest(MutliStepInputRequest.step, { inputId: param.id, step, data: state });
+ if (inputStep && inputStep.hasOwnProperty('items')) {
+ const quickPickStep = inputStep as QuickPickStep;
+ state[inputStep.stepId] = await input.showQuickPick({
+ title: param.title,
+ step,
+ totalSteps: quickPickStep.totalSteps,
+ placeholder: quickPickStep.placeHolder,
+ items: quickPickStep.items,
+ canSelectMany: quickPickStep.canPickMany,
+ selectedItems: quickPickStep.items.filter(item => item.picked)
+ });
+ return (input: MultiStepInput) => nextStep(input, step + 1, state);
+ } else if (inputStep && inputStep.hasOwnProperty('value')) {
+ const inputBoxStep = inputStep as InputBoxStep;
+ state[inputStep.stepId] = await input.showInputBox({
+ title: param.title,
+ step,
+ totalSteps: inputBoxStep.totalSteps,
+ value: state[inputStep.stepId] as string || inputBoxStep.value,
+ prompt: inputBoxStep.prompt,
+ password: inputBoxStep.password,
+ validate: (val) => {
+ const d = { ...state };
+ d[inputStep.stepId] = val;
+ return c.sendRequest(MutliStepInputRequest.validate, { inputId: param.id, step, data: d });
+ }
+ });
+ return (input: MultiStepInput) => nextStep(input, step + 1, state);
+ }
+ }
+ await MultiStepInput.run(input => nextStep(input, 1, data));
+ return data;
});
c.onNotification(TestProgressNotification.type, param => {
if (testAdapter) {
diff --git a/java/java.lsp.server/vscode/src/protocol.ts b/java/java.lsp.server/vscode/src/protocol.ts
index 87f8112c63..bf72ffa1e2 100644
--- a/java/java.lsp.server/vscode/src/protocol.ts
+++ b/java/java.lsp.server/vscode/src/protocol.ts
@@ -65,6 +65,10 @@ export namespace StatusMessageRequest {
};
export interface ShowQuickPickParams {
+ /**
+ * An optional title of the quick pick.
+ */
+ title?: string;
/**
* A string to show as placeholder in the input box to guide the user what to pick on.
*/
@@ -85,6 +89,10 @@ export namespace QuickPickRequest {
export interface ShowInputBoxParams {
/**
+ * An optional title of the input box.
+ */
+ title?: string;
+ /**
* The text to display underneath the input box.
*/
prompt: string;
@@ -102,6 +110,38 @@ export namespace InputBoxRequest {
export const type = new ProtocolRequestType<ShowInputBoxParams, string | undefined, never, void, void>('window/showInputBox');
}
+export interface ShowMutliStepInputParams {
+ /**
+ * ID of the input.
+ */
+ id: string;
+ /**
+ * An optional title.
+ */
+ title?: string;
+}
+
+export interface InputCallbackParams {
+ inputId : string;
+ step: number;
+ data: { [name: string]: readonly vscode.QuickPickItem[] | string };
+}
+
+export interface StepInfo {
+ totalSteps: number;
+ stepId: string;
+}
+
+export type QuickPickStep = StepInfo & ShowQuickPickParams;
+
+export type InputBoxStep = StepInfo & ShowInputBoxParams;
+
+export namespace MutliStepInputRequest {
+ export const type = new ProtocolRequestType<ShowMutliStepInputParams, { [name: string]: readonly vscode.QuickPickItem[] | string }, never, void, void>('window/showMultiStepInput');
+ export const step = new ProtocolRequestType<InputCallbackParams, QuickPickStep | InputBoxStep | undefined, never, void, void>('input/step');
+ export const validate = new ProtocolRequestType<InputCallbackParams, string | undefined, never, void, void>('input/validate');
+}
+
export interface TestProgressParams {
uri: string;
suite: TestSuite;
diff --git a/java/java.lsp.server/vscode/src/utils.ts b/java/java.lsp.server/vscode/src/utils.ts
new file mode 100644
index 0000000000..d13ff844ec
--- /dev/null
+++ b/java/java.lsp.server/vscode/src/utils.ts
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import * as vscode from 'vscode';
+
+class InputFlowAction {
+ static back = new InputFlowAction();
+ static cancel = new InputFlowAction();
+ static resume = new InputFlowAction();
+}
+
+export type InputStep = (input: MultiStepInput) => Thenable<InputStep | void>;
+
+interface QuickPickParameters<T extends vscode.QuickPickItem> {
+ title: string | undefined;
+ step: number;
+ totalSteps: number;
+ items: T[];
+ placeholder: string;
+ canSelectMany?: boolean;
+ selectedItems?: readonly T[];
+ buttons?: vscode.QuickInputButton[];
+ shouldResume?: () => Thenable<boolean>;
+}
+
+interface InputBoxParameters {
+ title: string | undefined;
+ step: number;
+ totalSteps: number;
+ value: string;
+ prompt: string;
+ validate: (value: string) => Promise<string | undefined>;
+ password?: boolean;
+ buttons?: vscode.QuickInputButton[];
+ shouldResume?: () => Thenable<boolean>;
+}
+
+export class MultiStepInput {
+
+ static async run(start: InputStep) {
+ const input = new MultiStepInput();
+ return input.stepThrough(start);
+ }
+
+ private current?: vscode.QuickInput;
+ private steps: InputStep[] = [];
+
+ private async stepThrough(start: InputStep) {
+ let step: InputStep | void = start;
+ while (step) {
+ this.steps.push(step);
+ if (this.current) {
+ this.current.enabled = false;
+ this.current.busy = true;
+ }
+ try {
+ step = await step(this);
+ } catch (err) {
+ if (err === InputFlowAction.back) {
+ this.steps.pop();
+ step = this.steps.pop();
+ } else if (err === InputFlowAction.resume) {
+ step = this.steps.pop();
+ } else if (err === InputFlowAction.cancel) {
+ step = undefined;
+ } else {
+ throw err;
+ }
+ }
+ }
+ if (this.current) {
+ this.current.dispose();
+ }
+ }
+
+ async showQuickPick<T extends vscode.QuickPickItem, P extends QuickPickParameters<T>>({ title, step, totalSteps, items, selectedItems, placeholder, canSelectMany, buttons, shouldResume }: P) {
+ const disposables: vscode.Disposable[] = [];
+ try {
+ return await new Promise<readonly T[] | (P extends { buttons: (infer I)[] } ? I : never)>((resolve, reject) => {
+ const input = vscode.window.createQuickPick<T>();
+ input.title = title;
+ input.step = step;
+ input.totalSteps = totalSteps;
+ input.placeholder = placeholder;
+ input.items = items;
+ if (canSelectMany) {
+ input.canSelectMany = canSelectMany;
+ }
+ if (selectedItems) {
+ input.selectedItems = selectedItems;
+ }
+ input.buttons = [
+ ...(this.steps.length > 1 ? [vscode.QuickInputButtons.Back] : []),
+ ...(buttons || [])
+ ];
+ input.ignoreFocusOut = true;
+ disposables.push(
+ input.onDidTriggerButton(item => {
+ if (item === vscode.QuickInputButtons.Back) {
+ reject(InputFlowAction.back);
+ } else {
+ resolve(<any>item);
+ }
+ }),
+ input.onDidAccept(() => {
+ resolve(input.selectedItems);
+ }),
+ input.onDidHide(() => {
+ (async () => {
+ reject(shouldResume && await shouldResume() ? InputFlowAction.resume : InputFlowAction.cancel);
+ })()
+ .catch(reject);
+ })
+ );
+ if (this.current) {
+ this.current.dispose();
+ }
+ this.current = input;
+ this.current.show();
+ });
+ } finally {
+ disposables.forEach(d => d.dispose());
+ }
+ }
+
+ async showInputBox<P extends InputBoxParameters>({ title, step, totalSteps, value, prompt, validate, password, buttons, shouldResume }: P) {
+ const disposables: vscode.Disposable[] = [];
+ try {
+ return await new Promise<string | (P extends { buttons: (infer I)[] } ? I : never)>((resolve, reject) => {
+ const input = vscode.window.createInputBox();
+ input.title = title;
+ input.step = step;
+ input.totalSteps = totalSteps;
+ input.value = value || '';
+ input.prompt = prompt;
+ if (password) {
+ input.password = password;
+ }
+ input.buttons = [
+ ...(this.steps.length > 1 ? [vscode.QuickInputButtons.Back] : []),
+ ...(buttons || [])
+ ];
+ input.ignoreFocusOut = true;
+ // let validating = validate('');
+ disposables.push(
+ input.onDidTriggerButton(item => {
+ if (item === vscode.QuickInputButtons.Back) {
+ reject(InputFlowAction.back);
+ } else {
+ resolve(<any>item);
+ }
+ }),
+ input.onDidAccept(async () => {
+ const value = input.value;
+ input.enabled = false;
+ input.busy = true;
+ const validationMessage = await validate(value);
+ if (validationMessage) {
+ input.validationMessage = validationMessage;
+ } else {
+ resolve(value);
+ }
+ input.enabled = true;
+ input.busy = false;
+ }),
+ // input.onDidChangeValue(async text => {
+ // const current = validate(text);
+ // validating = current;
+ // const validationMessage = await current;
+ // if (current === validating) {
+ // input.validationMessage = validationMessage;
+ // }
+ // }),
+ input.onDidHide(() => {
+ (async () => {
+ reject(shouldResume && await shouldResume() ? InputFlowAction.resume : InputFlowAction.cancel);
+ })()
+ .catch(reject);
+ })
+ );
+ if (this.current) {
+ this.current.dispose();
+ }
+ this.current = input;
+ this.current.show();
+ });
+ } finally {
+ disposables.forEach(d => d.dispose());
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists