Convert token changes to LeafOps.
(
&mut self,
token_changes: &[TokenChange<'a>],
)
| 445 | |
| 446 | /// Convert token changes to LeafOps. |
| 447 | fn convert_token_changes<'a>( |
| 448 | &mut self, |
| 449 | token_changes: &[TokenChange<'a>], |
| 450 | ) -> ConversionResult<Vec<LeafOp>> { |
| 451 | let mut leaf_ops = Vec::new(); |
| 452 | |
| 453 | for tc in token_changes { |
| 454 | match tc { |
| 455 | TokenChange::Unchanged { token, .. } => { |
| 456 | if self.config.preserve_unchanged { |
| 457 | // Include unchanged tokens as inserts for complete reconstruction |
| 458 | if self.should_include_token(token.kind()) { |
| 459 | let _leaf_id = self.allocator.alloc_leaf(); |
| 460 | leaf_ops.push(LeafOp::Insert { |
| 461 | after: None, |
| 462 | kind: token.kind(), |
| 463 | content: token.content().to_vec(), |
| 464 | }); |
| 465 | self.stats.tokens_unchanged += 1; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | TokenChange::Inserted { token, .. } => { |
| 471 | if self.should_include_token(token.kind()) { |
| 472 | let _leaf_id = self.allocator.alloc_leaf(); |
| 473 | leaf_ops.push(LeafOp::Insert { |
| 474 | after: None, |
| 475 | kind: token.kind(), |
| 476 | content: token.content().to_vec(), |
| 477 | }); |
| 478 | self.stats.tokens_inserted += 1; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | TokenChange::Deleted { token, .. } => { |
| 483 | // For deletions, we record what was deleted |
| 484 | if self.should_include_token(token.kind()) { |
| 485 | let leaf_id = self.allocator.alloc_leaf(); |
| 486 | leaf_ops.push(LeafOp::Delete { leaf: leaf_id }); |
| 487 | self.stats.tokens_deleted += 1; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | TokenChange::Replaced { new_token, .. } => { |
| 492 | if self.should_include_token(new_token.kind()) { |
| 493 | let leaf_id = self.allocator.alloc_leaf(); |
| 494 | |
| 495 | if self.config.use_replace_ops { |
| 496 | // Use a single Replace operation |
| 497 | leaf_ops.push(LeafOp::Replace { |
| 498 | leaf: leaf_id, |
| 499 | new_content: new_token.content().to_vec(), |
| 500 | }); |
| 501 | self.stats.tokens_replaced += 1; |
| 502 | } else { |
| 503 | // Use Delete + Insert pair |
| 504 | leaf_ops.push(LeafOp::Delete { leaf: leaf_id }); |
no test coverage detected