If prompt closed without Apply or Preview don't apply changes
This commit is contained in:
@@ -423,13 +423,12 @@ public class RewriteRecipeRepository {
|
||||
String changeAnnotationId = UUID.randomUUID().toString();
|
||||
Optional<WorkspaceEdit> we = computeWorkspaceEdit(r, sources, progressTask, changeAnnotationId);
|
||||
if (we.isPresent()) {
|
||||
CompletableFuture<WorkspaceEdit> 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<WorkspaceEdit> askForPreview(WorkspaceEdit workspaceEdit, String changeAnnotationId) {
|
||||
private CompletableFuture<Optional<WorkspaceEdit>> 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.<Boolean>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<Object> applyEdit(Optional<WorkspaceEdit> we, IndefiniteProgressTask progressTask, String title) {
|
||||
|
||||
Reference in New Issue
Block a user