MCPcopy Create free account
hub / github.com/Eeive/Evcode-ide / get_diff

Method get_diff

src/snap.rs:44–64  ·  view source on GitHub ↗
(&self, path: &str, current_content: &str)

Source from the content-addressed store, hash-verified

42 }
43
44 pub fn get_diff(&self, path: &str, current_content: &str) -> Option<Vec<DiffLine>> {
45 let snap = self.snapshots.get(path)?;
46 let old_lines: Vec<&str> = snap.content.lines().collect();
47 let new_lines: Vec<&str> = current_content.lines().collect();
48
49 let mut diff = Vec::new();
50 let max_len = old_lines.len().max(new_lines.len());
51 for i in 0..max_len {
52 match (old_lines.get(i), new_lines.get(i)) {
53 (Some(o), Some(n)) if o == n => diff.push(DiffLine::Unchanged(o.to_string())),
54 (Some(o), Some(n)) => {
55 diff.push(DiffLine::Removed(o.to_string()));
56 diff.push(DiffLine::Added(n.to_string()));
57 }
58 (Some(o), None) => diff.push(DiffLine::Removed(o.to_string())),
59 (None, Some(n)) => diff.push(DiffLine::Added(n.to_string())),
60 (None, None) => {}
61 }
62 }
63 Some(diff)
64 }
65
66 pub fn save_all_to_disk(&self) {
67 let mut path = dirs::data_local_dir().unwrap_or_else(|| PathBuf::from("."));

Callers 1

handle_keyMethod · 0.80

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected