resolveFromHunk tries to find startLine/endLine by matching ExistingCode against hunk lines. It tries the new-side first (context + added lines → new-file line numbers), then falls back to old-side (context + deleted → old-file line numbers).
(d *model.Diff, cm *model.LlmComment)
| 83 | // new-file line numbers), then falls back to old-side (context + deleted → |
| 84 | // old-file line numbers). |
| 85 | func resolveFromHunk(d *model.Diff, cm *model.LlmComment) bool { |
| 86 | hunks := ParseHunks(d.Diff) |
| 87 | if len(hunks) == 0 { |
| 88 | return false |
| 89 | } |
| 90 | |
| 91 | targetLines := splitAndNormalize(cm.ExistingCode) |
| 92 | if len(targetLines) == 0 { |
| 93 | return false |
| 94 | } |
| 95 | |
| 96 | for i := range hunks { |
| 97 | newSide := extractSideLines(&hunks[i], true) |
| 98 | if start, end, ok := matchConsecutive(newSide, targetLines); ok { |
| 99 | cm.StartLine = start |
| 100 | cm.EndLine = end |
| 101 | return true |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | for i := range hunks { |
| 106 | oldSide := extractSideLines(&hunks[i], false) |
| 107 | if start, end, ok := matchConsecutive(oldSide, targetLines); ok { |
| 108 | cm.StartLine = start |
| 109 | cm.EndLine = end |
| 110 | return true |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return false |
| 115 | } |
| 116 | |
| 117 | // extractSideLines extracts one side of the diff from a hunk. |
| 118 | // When newSide is true, returns context+added lines with new-file line numbers. |
no test coverage detected