You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
helix/helix-core/src
Michael Davis d5f17d3f69
Fix initial highlight layer sort order (#5196)
The purpose of this change is to remove the mutable self borrow on
`HighlightIterLayer::sort_key` so that we can sort layers with the
correct ordering using the `Vec::sort` function family.
`HighlightIterLayer::sort_key` needs `&mut self` since it calls
`Peekable::peek` which needs `&mut self`. `Vec::sort` functions
only give immutable borrows of the elements to ensure the
correctness of the sort.

We could instead approach this by creating an eager Peekable and using
that instead of `std::iter::Peekable` to wrap `QueryCaptures`:

```rust
struct EagerPeekable<I: Iterator> {
    iter: I,
    peeked: Option<I::Item>,
}

impl<I: Iterator> EagerPeekable<I> {
    fn new(mut iter: I) -> Self {
        let peeked = iter.next();
        Self { iter, peeked }
    }

    fn peek(&self) -> Option<&I::Item> {
        self.peeked.as_ref()
    }
}

impl<I: Iterator> Iterator for EagerPeekable<I> {
    type Item = I::Item;

    fn next(&mut self) -> Option<Self::Item> {
        std::mem::replace(&mut self.peeked, self.iter.next())
    }
}
```

This would be a cleaner approach (notice how `EagerPeekable::peek`
takes `&self` rather than `&mut self`), however this doesn't work in
practice because the Items emitted by the `tree_sitter::QueryCaptures`
Iterator must be consumed before the next Item is returned.
`Iterator::next` on `tree_sitter::QueryCaptures` modifies the
`QueryMatch` returned by the last call of `next`. This behavior is
not currently reflected in the lifetimes/structure of `QueryCaptures`.

This fixes an issue with layers being out of order when using combined
injections since the old code only checked the first range in the
layer. Layers being out of order could cause missing highlights for
combined-injections content.
1 year ago
..
doc_formatter rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
increment Separate jump behavior from increment/decrement (#4123) 1 year ago
auto_pairs.rs Fix erroneous indent between closers of auto-pairs (#5330) 2 years ago
chars.rs Temporarily turn on unicode-lines 2 years ago
comment.rs core: Move state into the history module 2 years ago
config.rs Add support for local language configuration (#1249) 2 years ago
diagnostic.rs feat(lsp): add support for lsp Diagnostic{}.data (#4935) 2 years ago
diff.rs delete outdated reference to cessen/ropey#25 (#4928) 2 years ago
doc_formatter.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
graphemes.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
history.rs Fix transaction composition order in History::changes_since (#4981) 2 years ago
indent.rs Fix panic from indenting on tree with errors 2 years ago
lib.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
line_ending.rs Resolve a bunch of upcoming clippy lints 2 years ago
macros.rs Split parts of helix-term into helix-view. 4 years ago
match_brackets.rs Fix match brackets comment (#1346) 3 years ago
movement.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
object.rs Fix edge-case in tree-sitter expand_selection selection command (#2877) 2 years ago
path.rs Add workspace and document diagnostics picker (#2013) 2 years ago
position.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
register.rs Refactor blackhole register (#4504) 2 years ago
search.rs Jump to the next number on the line before incrementing (#1778) 2 years ago
selection.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
shellwords.rs Capture word parts while calculating shellwords (#4632) 2 years ago
surround.rs Resolve a bunch of upcoming clippy lints 2 years ago
syntax.rs Fix initial highlight layer sort order (#5196) 1 year ago
test.rs Run clippy on workspace in CI (#4614) 2 years ago
text_annotations.rs rework positioning/rendering and enable softwrap/virtual text (#5420) 1 year ago
textobject.rs Adjust `m` textobject description and minor code clarification (#3343) 2 years ago
transaction.rs Significantly improve performance of `:reload` (#4457) 2 years ago
wrap.rs add reflow command (#2128) 2 years ago