diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteRecipeRepository.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteRecipeRepository.java index 863c5f001..a6374362f 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteRecipeRepository.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteRecipeRepository.java @@ -423,13 +423,12 @@ public class RewriteRecipeRepository { String changeAnnotationId = UUID.randomUUID().toString(); Optional we = computeWorkspaceEdit(r, sources, progressTask, changeAnnotationId); if (we.isPresent()) { - CompletableFuture editFuture = askForPreview ? askForPreview(we.get(), changeAnnotationId) : CompletableFuture.completedFuture(we.get()); - return editFuture.thenApply(Optional::of); + return askForPreview ? askForPreview(we.get(), changeAnnotationId) : CompletableFuture.completedFuture(we); } return CompletableFuture.completedFuture(Optional.empty()); } - private CompletableFuture askForPreview(WorkspaceEdit workspaceEdit, String changeAnnotationId) { + private CompletableFuture> askForPreview(WorkspaceEdit workspaceEdit, String changeAnnotationId) { return server.getClientCapabilities().thenApply(capabilities -> { WorkspaceEditChangeAnnotationSupportCapabilities changeAnnotationSupport = capabilities.getWorkspace().getWorkspaceEdit().getChangeAnnotationSupport(); return changeAnnotationSupport != null && changeAnnotationSupport.getGroupsOnLabel() != null && changeAnnotationSupport.getGroupsOnLabel().booleanValue(); @@ -441,15 +440,23 @@ public class RewriteRecipeRepository { messageParams.setType(MessageType.Info); messageParams.setMessage("Do you want to preview changes before applying or apply right away?"); messageParams.setActions(List.of(applyChanges, previewChanges)); - return server.getClient().showMessageRequest(messageParams).thenApply(previewChanges::equals); + return server.getClient().showMessageRequest(messageParams).thenApply(ma -> { + if (previewChanges.equals(ma) ) { + return Optional.of(true); + } else if (applyChanges.equals(ma)) { + return Optional.of(false); + } else { + return Optional.empty(); + } + }); } else { - return CompletableFuture.completedFuture(false); + return CompletableFuture.completedFuture(Optional.of(false)); } - }).thenApply(needsConfirmation -> { + }).thenApply(optNeedsConfirmation -> optNeedsConfirmation.map(needsConfirmation -> { ChangeAnnotation changeAnnotation = workspaceEdit.getChangeAnnotations().get(changeAnnotationId); changeAnnotation.setNeedsConfirmation(needsConfirmation); return workspaceEdit; - }); + })); } private CompletableFuture applyEdit(Optional we, IndefiniteProgressTask progressTask, String title) {