Mountain/ApplicationState/DTO/
RPCModelContentChangeDTO.rs

1//! # RPCModelContentChangeDTO
2//!
3//! # RESPONSIBILITY
4//! - Data transfer object for text document changes
5//! - Serializable format for gRPC/IPC transmission
6//! - Used by Mountain to apply delta changes to documents
7//! - Compatible with VS Code's LSP RPC protocol
8//!
9//! # FIELDS
10//! - Range: The range of text to replace
11//! - Text: The new text to insert
12
13use serde::Deserialize;
14
15use super::RPCRangeDTO::RPCRangeDTO;
16
17/// Represents a single text change operation, including the range to be
18/// replaced and the new text to insert. This is part of a collection sent when
19/// a document is edited.
20#[derive(Deserialize, Debug, Clone)]
21#[serde(rename_all = "PascalCase")]
22pub struct RPCModelContentChangeDTO {
23	/// The range of text to replace
24	pub Range:RPCRangeDTO,
25
26	/// The new text to insert (may be empty deletion)
27	pub Text:String,
28}
29
30impl RPCModelContentChangeDTO {
31	/// Creates a new RPCModelContentChangeDTO with validation.
32	///
33	/// # Arguments
34	/// * `Range` - The range to replace
35	/// * `Text` - The text to insert
36	///
37	/// # Returns
38	/// Result containing the DTO or validation error
39	pub fn New(Range:RPCRangeDTO, Text:String) -> Result<Self, String> {
40		// Text is allowed to be empty (for deletion operations)
41		Ok(Self { Range, Text })
42	}
43
44	/// Checks if this is a deletion operation (empty text).
45	pub fn IsDeletion(&self) -> bool { self.Text.is_empty() }
46
47	/// Checks if this is an insertion operation (empty range).
48	pub fn IsInsertion(&self) -> bool { self.Range.IsEmpty() && !self.Text.is_empty() }
49
50	/// Checks if this is a replacement operation (non-empty range and text).
51	pub fn IsReplacement(&self) -> bool { !self.Range.IsEmpty() && !self.Text.is_empty() }
52}