MCPcopy Create free account
hub / github.com/alibaba/open-code-review / resolveFromHunk

Function resolveFromHunk

internal/diff/resolver.go:82–112  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

ResolveLineNumbersFunction · 0.85
ResolveCommentFunction · 0.85

Calls 4

ParseHunksFunction · 0.85
extractSideLinesFunction · 0.85
matchConsecutiveFunction · 0.85
splitAndNormalizeFunction · 0.70

Tested by

no test coverage detected