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

Function resolveFromHunk

internal/diff/resolver.go:85–115  ·  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

83// new-file line numbers), then falls back to old-side (context + deleted →
84// old-file line numbers).
85func 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.

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