1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::range::Range;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
8pub struct Edit {
9 pub range: Range,
10 pub kind: EditKind,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
14pub enum EditKind {
15 Insert { text: String },
17 Delete,
19 Replace { text: String },
21}
22
23impl Edit {
24 #[must_use]
25 pub fn insert(at: crate::position::Position, text: impl Into<String>) -> Self {
26 Self {
27 range: Range::point(at),
28 kind: EditKind::Insert { text: text.into() },
29 }
30 }
31
32 #[must_use]
33 pub fn delete(range: Range) -> Self {
34 Self {
35 range,
36 kind: EditKind::Delete,
37 }
38 }
39
40 #[must_use]
41 pub fn replace(range: Range, text: impl Into<String>) -> Self {
42 Self {
43 range,
44 kind: EditKind::Replace { text: text.into() },
45 }
46 }
47}