helix
helix copied to clipboard
Rewrite Merge to take two HighlightEvent Iterators
Currently, the HighlightEvent merge function overlays spans (Vec<(usize, std::ops::Range<usize>)> on an Iterator of HighlightEvent. The current merge doesn't handle overlapping spans well though, specifically with LSP diagnostics:
- diagnostic ranges may be discarded if they overlap
- ghost text may appear when a language server sends overlapping diagnostics at the end of a document
This merge function takes two HighlightEvent Iterators which may themselves have overlapping highlights and produces a new Iterator with highlights from right overlaid on left. Also included is a new Iterator that properly subslices overlapping ranges in a Vec<(usize, std::ops::Range<usize>) which can be passed to the merge function and satisfies all of merge's invariants and assumptions.
The new merge is more complicated and it looks like we get dinged for the extra VecDeques but otherwise the performance looks comparable. I couldn't find any noticeable changes in the flamegraph except for two new tiny slivers for VecDeque::extend.
Fixes https://github.com/helix-editor/helix/issues/2248 I rebased #2857 on this and it works well and actually the types work out much nicer than that branch's merge function.