CoalesceMatches = function (matches) {
    var blocks = matches.map(MatchToLines),
        res = [],
        current;
    // go through each block of lines and see if it overlaps
    // with the previous.
    for (var i = 0, n = blocks.length; i < n; i++) {
        var block = blocks[i],
            max = current ? current[current.length - 1].Number : -1;
        // if the first line in the block is before the last line in
        // current, we'll be merging.
        if (block[0].Number <= max) {
            block.forEach(function (line) {
                if (line.Number > max) {
                    current.push(line);
                } else if (current && line.Match) {
                    // we have to go back into current and make sure that matches
                    // are properly marked.
                    current[
                        current.length - 1 - (max - line.Number)
                    ].Match = true;
                }
            });
        } else {
            if (current) {
                res.push(current);
            }
            current = block;
        }
    }

    if (current) {
        res.push(current);
    }

    return res;
}
Take several lists of lines each representing a matching block and merge overlapping
blocks together. A good example of this is when you have a match on two consecutive
lines. We will merge those into a singular block.

TODO(knorton): This code is a bit skanky. I wrote it while sleepy. It can surely be
made simpler.