DingoLineToGoLine converts a 1-indexed Dingo line to the corresponding Go line. For lines inside a transform (match, error prop, etc.), returns a proportionally mapped Go line within the transform's Go line range. For lines outside transforms, uses cumulative expansion from preceding transforms.
(dingoLine int)
| 591 | // mapped Go line within the transform's Go line range. |
| 592 | // For lines outside transforms, uses cumulative expansion from preceding transforms. |
| 593 | func (r *Reader) DingoLineToGoLine(dingoLine int) int { |
| 594 | r.mu.RLock() |
| 595 | defer r.mu.RUnlock() |
| 596 | |
| 597 | goLineCount := len(r.goLines) |
| 598 | if goLineCount == 0 { |
| 599 | return dingoLine |
| 600 | } |
| 601 | |
| 602 | // Check if this Dingo line is inside any transform |
| 603 | for _, m := range r.lineMappings { |
| 604 | dingoStart := int(m.DingoLine) |
| 605 | // DingoLineCount of 0 means 1 line (backwards compat with old .dmap files) |
| 606 | dingoLineCount := int(m.DingoLineCount) |
| 607 | if dingoLineCount == 0 { |
| 608 | dingoLineCount = 1 |
| 609 | } |
| 610 | dingoEnd := dingoStart + dingoLineCount - 1 |
| 611 | |
| 612 | if dingoLine >= dingoStart && dingoLine <= dingoEnd { |
| 613 | // Line is inside this transform - map proportionally |
| 614 | offset := dingoLine - dingoStart |
| 615 | goLinesInTransform := int(m.GoLineEnd-m.GoLineStart) + 1 |
| 616 | |
| 617 | // Linear mapping: offset within Dingo range -> offset within Go range |
| 618 | // For single-line transforms, offset=0 -> return GoLineStart |
| 619 | // For multi-line transforms, map proportionally |
| 620 | if dingoLineCount == 1 { |
| 621 | return int(m.GoLineStart) |
| 622 | } |
| 623 | goOffset := (offset * goLinesInTransform) / dingoLineCount |
| 624 | return int(m.GoLineStart) + goOffset |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // Line is outside all transforms - calculate using cumulative expansion |
| 629 | baseOffset := r.calculateBaseOffset() |
| 630 | |
| 631 | transformShift := 0 |
| 632 | for _, m := range r.lineMappings { |
| 633 | dingoStart := int(m.DingoLine) |
| 634 | // DingoLineCount of 0 means 1 line (backwards compat) |
| 635 | dingoLineCount := int(m.DingoLineCount) |
| 636 | if dingoLineCount == 0 { |
| 637 | dingoLineCount = 1 |
| 638 | } |
| 639 | dingoEnd := dingoStart + dingoLineCount - 1 |
| 640 | |
| 641 | // Only count transforms that END before the target line |
| 642 | if dingoEnd < dingoLine { |
| 643 | goLines := int(m.GoLineEnd-m.GoLineStart) + 1 |
| 644 | // Expansion = Go lines produced - Dingo lines consumed |
| 645 | transformShift += goLines - dingoLineCount |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | goLine := dingoLine + baseOffset + transformShift |
| 650 | if goLine < 1 { |
no test coverage detected