Skip to main content

parse_unified_diff_ranges

Function parse_unified_diff_ranges 

Source
pub fn parse_unified_diff_ranges(patch: &str, file: &str) -> Vec<ChangedRange>
Expand description

Extract changed line ranges from a unified diff patch for one file.

Reads the + side of each @@ -a,b +c,d @@ header, so the ranges refer to line numbers in the new file — the same numbering the indexed graph uses.

The full hunk span is returned, including its context lines. Context is deliberately kept: a hunk that only deletes lines has no added lines to point at, but the deletion still changes the enclosing symbol, and the surrounding context is what locates it. Over-including by the three context lines either side is immaterial next to the alternative of taking the whole file.

Malformed headers are skipped rather than failing the parse — a diff that partially parses still yields a far better radius than no ranges at all.