CommonLibrary/Workspace/ApplyWorkspaceEdit.rs
1//! # ApplyWorkspaceEdit Effect
2//!
3//! Defines the `ActionEffect` for applying a complex, multi-file workspace
4//! edit.
5
6use std::sync::Arc;
7
8use super::WorkspaceEditApplier::WorkspaceEditApplier;
9use crate::{
10 DTO::WorkspaceEditDTO::WorkspaceEditDTO,
11 Effect::ActionEffect::ActionEffect,
12 Error::CommonError::CommonError,
13};
14
15/// Creates an effect that, when executed, will apply a `WorkspaceEdit` to the
16/// workspace.
17///
18/// A `WorkspaceEdit` is a batch of operations that can include text edits to
19/// multiple files and filesystem operations like creating, deleting, or
20/// renaming files. This effect uses the dedicated `WorkspaceEditApplier`
21/// capability.
22///
23/// # Parameters
24/// * `EditDTO`: The `WorkspaceEditDTO` representing the batch of edits to
25/// apply.
26///
27/// # Returns
28/// An `ActionEffect` that resolves with a `bool` indicating whether the entire
29/// edit was applied successfully.
30pub fn ApplyWorkspaceEdit(EditDTO:WorkspaceEditDTO) -> ActionEffect<Arc<dyn WorkspaceEditApplier>, CommonError, bool> {
31 ActionEffect::New(Arc::new(move |Applier:Arc<dyn WorkspaceEditApplier>| {
32 let EditDTOClone = EditDTO.clone();
33
34 Box::pin(async move { Applier.ApplyWorkspaceEdit(EditDTOClone).await })
35 }))
36}