#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Anchor {
pub line: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Cursor {
Bof,
Eof,
BeforeAnchor(Anchor),
AfterAnchor(Anchor),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InsertMode {
Replacement,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockMode {
InsertAfter,
}
#[derive(Debug, Clone)]
pub enum Edit {
Insert {
cursor: Cursor,
text: String,
line_num: u32,
index: usize,
mode: Option<InsertMode>,
},
Delete {
anchor: Anchor,
line_num: u32,
index: usize,
old_assertion: Option<String>,
},
}
impl Edit {
pub fn line_num(&self) -> u32 {
match self {
Edit::Insert { line_num, .. } | Edit::Delete { line_num, .. } => *line_num,
}
}
pub fn anchor_line(&self) -> u32 {
match self {
Edit::Insert { cursor, .. } => match cursor {
Cursor::BeforeAnchor(a) | Cursor::AfterAnchor(a) => a.line,
Cursor::Bof => 0,
Cursor::Eof => u32::MAX,
},
Edit::Delete { anchor, .. } => anchor.line,
}
}
pub fn index(&self) -> usize {
match self {
Edit::Insert { index, .. } | Edit::Delete { index, .. } => *index,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ApplyResult {
pub text: String,
pub first_changed_line: Option<u32>,
pub warnings: Vec<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ParsedRange {
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone, Default)]
pub struct SplitOptions {
pub root: Option<std::path::PathBuf>,
}
#[derive(Debug, Clone, Default)]
pub struct CompactDiffPreview {
pub lines: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct CompactDiffOptions {
pub max_unchanged_context: usize,
}
impl Default for CompactDiffOptions {
fn default() -> Self {
Self {
max_unchanged_context: 3,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct BlockSpan {
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone)]
pub struct BlockResolution {
pub anchor_line: u32,
pub start: u32,
pub end: u32,
pub op: BlockOp,
}
#[derive(Debug, Clone, Copy)]
pub enum BlockOp {
Replace,
Delete,
InsertAfter,
}
#[derive(Debug, Clone)]
pub struct BlockResolverRequest {
pub text: String,
pub anchor_line: u32,
}
pub type BlockResolver =
std::sync::Arc<dyn Fn(&BlockResolverRequest) -> Option<BlockSpan> + Send + Sync>;