MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / generate_diff

Function generate_diff

crates/opencode-tool/src/apply_patch.rs:729–752  ·  view source on GitHub ↗
(path: &str, old: &str, new: &str)

Source from the content-addressed store, hash-verified

727}
728
729fn generate_diff(path: &str, old: &str, new: &str) -> String {
730 let old_lines: Vec<&str> = old.lines().collect();
731 let new_lines: Vec<&str> = new.lines().collect();
732
733 let mut diff = format!("--- a/{}\n+++ b/{}\n", path, path);
734
735 let old_count = old_lines.len();
736 let new_count = new_lines.len();
737
738 diff.push_str(&format!(
739 "@@ -1,{} +1,{} @@\n",
740 old_count.max(1),
741 new_count.max(1)
742 ));
743
744 for line in &old_lines {
745 diff.push_str(&format!("-{}\n", line));
746 }
747 for line in &new_lines {
748 diff.push_str(&format!("+{}\n", line));
749 }
750
751 diff
752}
753
754async fn collect_lsp_diagnostics_for_targets(
755 base_path: &Path,

Callers 1

process_file_patchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected