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

Function create_diff

crates/opencode-tool/src/write.rs:193–221  ·  view source on GitHub ↗
(filepath: &str, old_content: &str, new_content: &str)

Source from the content-addressed store, hash-verified

191}
192
193fn create_diff(filepath: &str, old_content: &str, new_content: &str) -> String {
194 let old_lines: Vec<&str> = old_content.lines().collect();
195 let new_lines: Vec<&str> = new_content.lines().collect();
196
197 let mut diff = format!("--- {}\n+++ {}\n", filepath, filepath);
198
199 let mut old_idx = 0;
200 let mut new_idx = 0;
201
202 while old_idx < old_lines.len() || new_idx < new_lines.len() {
203 if old_idx >= old_lines.len() {
204 diff.push_str(&format!("+{}\n", new_lines[new_idx]));
205 new_idx += 1;
206 } else if new_idx >= new_lines.len() {
207 diff.push_str(&format!("-{}\n", old_lines[old_idx]));
208 old_idx += 1;
209 } else if old_lines[old_idx] == new_lines[new_idx] {
210 old_idx += 1;
211 new_idx += 1;
212 } else {
213 diff.push_str(&format!("-{}\n", old_lines[old_idx]));
214 diff.push_str(&format!("+{}\n", new_lines[new_idx]));
215 old_idx += 1;
216 new_idx += 1;
217 }
218 }
219
220 diff
221}
222
223async fn get_lsp_diagnostics(path: &Path, ctx: &ToolContext) -> String {
224 #[cfg(feature = "lsp")]

Callers 1

executeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected