vvv-engine 0.2.0

Composes vvv plugins into refactoring pipelines
Documentation
//! What the user wants done, as data.
//!
//! An intent is built by the CLI from arguments, by a TUI from a form, or by
//! a client from JSON, and handed to the engine. Nothing here knows how the
//! intent is fulfilled.

use crate::capabilities::moves::{MoveIntent, MoveSymbolIntent};
use crate::capabilities::rename::RenameIntent;
use serde::{Deserialize, Serialize};

pub use crate::batch::BatchIntent;
pub use crate::rewrite::{RewriteIntent, RewriteOf};

/// Any mutating request, as one value: what history records, what a summary
/// renders, what a remote client sends.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(tag = "command", rename_all = "snake_case")]
pub enum Intent {
    Rewrite(RewriteIntent),
    Rename(RenameIntent),
    Move(MoveIntent),
    MoveSymbol(MoveSymbolIntent),
    /// Several intents planned in sequence, each against the state the
    /// previous one leaves, and applied as one.
    Batch(BatchIntent),
}

impl Intent {
    /// Add execution policy to a mutation description without executing it.
    pub fn into_request(self, apply: bool) -> crate::Request {
        match self {
            Self::Rename(intent) => crate::Request::Rename { intent, apply },
            Self::Move(intent) => crate::Request::Move { intent, apply },
            Self::MoveSymbol(intent) => crate::Request::MoveSymbol { intent, apply },
            Self::Rewrite(intent) => crate::Request::Rewrite { intent, apply },
            Self::Batch(intent) => crate::Request::Batch { intent, apply },
        }
    }
}

impl From<BatchIntent> for Intent {
    fn from(i: BatchIntent) -> Self {
        Self::Batch(i)
    }
}

impl From<RewriteIntent> for Intent {
    fn from(i: RewriteIntent) -> Self {
        Self::Rewrite(i)
    }
}

impl From<RenameIntent> for Intent {
    fn from(i: RenameIntent) -> Self {
        Self::Rename(i)
    }
}

impl From<MoveIntent> for Intent {
    fn from(i: MoveIntent) -> Self {
        Self::Move(i)
    }
}

impl From<MoveSymbolIntent> for Intent {
    fn from(i: MoveSymbolIntent) -> Self {
        Self::MoveSymbol(i)
    }
}