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