MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / print_semantic_word_diff_line

Function print_semantic_word_diff_line

atomic-cli/src/commands/diff/output.rs:295–336  ·  view source on GitHub ↗

Print a line with semantic token-level diff highlighting. Uses the semantic diff engine for precise token-level highlighting. This produces better results than the inline diff for code, as it understands token boundaries (identifiers, operators, strings, etc.) # Visual Pattern ```text - const result = calculateSum(a, b); <- light red background + const result = calculateSum(a, b, c);

(token_changes: &[TokenChange<'_>], is_deletion: bool)

Source from the content-addressed store, hash-verified

293/// ^^^^ <- dark green: ", c" added
294/// ```
295pub(crate) fn print_semantic_word_diff_line(token_changes: &[TokenChange<'_>], is_deletion: bool) {
296 for tc in token_changes {
297 match tc {
298 TokenChange::Unchanged { token, .. } => {
299 // Unchanged tokens - dim color for context
300 let text = token.as_str();
301 if is_deletion {
302 print!("\x1b[31m{}\x1b[0m", text); // Dim red for deletion context
303 } else {
304 print!("\x1b[32m{}\x1b[0m", text); // Dim green for insertion context
305 }
306 }
307 TokenChange::Deleted { token, .. } if is_deletion => {
308 // Deleted token - bright red with underline
309 let text = token.as_str();
310 print!("\x1b[91;1;4m{}\x1b[0m", text);
311 }
312 TokenChange::Inserted { token, .. } if !is_deletion => {
313 // Inserted token - bright green with underline
314 let text = token.as_str();
315 print!("\x1b[92;1;4m{}\x1b[0m", text);
316 }
317 TokenChange::Replaced {
318 old_token,
319 new_token,
320 ..
321 } => {
322 if is_deletion {
323 // Show old token in bright red with underline
324 let text = old_token.as_str();
325 print!("\x1b[91;1;4m{}\x1b[0m", text);
326 } else {
327 // Show new token in bright green with underline
328 let text = new_token.as_str();
329 print!("\x1b[92;1;4m{}\x1b[0m", text);
330 }
331 }
332 // Skip tokens that don't apply to this line type
333 TokenChange::Deleted { .. } | TokenChange::Inserted { .. } => {}
334 }
335 }
336}

Callers 2

print_word_diff_patchFunction · 0.85
print_unifiedMethod · 0.85

Calls 1

as_strMethod · 0.45

Tested by

no test coverage detected