session_core/
cell_file_changes.rs1use host::Host;
7use serde_json::{Value, json};
8
9pub const CONTEXT_LINES: usize = 2;
10pub const MAX_DIFF_LINES: usize = 400;
12
13pub fn details(host: &Host, lane: &str, mask: &dyn Fn(&str) -> String) -> Value {
16 let changes: Vec<Value> = host
17 .take_cell_writes(lane)
18 .into_iter()
19 .map(|write| {
20 let path =
21 host::file_hooks::inside(host.cwd(), &write.path).unwrap_or_else(|| write.path.display().to_string());
22 let mut change = json!({ "path": path, "created": write.created, "diff": null });
23 if let Some((before, after)) = &write.texts {
24 let (diff, _) = jsrt::diff::generate_diff_string(before, after, CONTEXT_LINES);
25 let diff = mask(&diff);
26 let lines: Vec<&str> = diff.split('\n').collect();
27 change["diff"] = json!(lines[..lines.len().min(MAX_DIFF_LINES)].join("\n"));
28 if lines.len() > MAX_DIFF_LINES {
29 change["omitted"] = json!(lines.len() - MAX_DIFF_LINES);
30 }
31 }
32 change
33 })
34 .collect();
35 if changes.is_empty() {
36 json!({})
37 } else {
38 json!({ "fileChanges": changes })
39 }
40}