Fix some issues with branch buffers (#18945)

* `Open Excerpts` command always opens the locations in the base buffer
* LSP features like document-highlights, go-to-def, and inlay hints work
correctly in branch buffers
* Other LSP features like completions, code actions, and rename are
disabled in branch buffers

Release Notes:

- N/A
This commit is contained in:
Max Brunsfeld 2024-10-09 16:55:25 -07:00 committed by GitHub
parent cae548a50d
commit 53cc82b132
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 554 additions and 267 deletions

View file

@ -2439,6 +2439,42 @@ impl BufferSnapshot {
}
false
}
pub fn range_to_version(&self, range: Range<usize>, version: &clock::Global) -> Range<usize> {
let mut offsets = self.offsets_to_version([range.start, range.end], version);
offsets.next().unwrap()..offsets.next().unwrap()
}
/// Converts the given sequence of offsets into their corresponding offsets
/// at a prior version of this buffer.
pub fn offsets_to_version<'a>(
&'a self,
offsets: impl 'a + IntoIterator<Item = usize>,
version: &'a clock::Global,
) -> impl 'a + Iterator<Item = usize> {
let mut edits = self.edits_since(version).peekable();
let mut last_old_end = 0;
let mut last_new_end = 0;
offsets.into_iter().map(move |new_offset| {
while let Some(edit) = edits.peek() {
if edit.new.start > new_offset {
break;
}
if edit.new.end <= new_offset {
last_new_end = edit.new.end;
last_old_end = edit.old.end;
edits.next();
continue;
}
let overshoot = new_offset - edit.new.start;
return (edit.old.start + overshoot).min(edit.old.end);
}
last_old_end + new_offset.saturating_sub(last_new_end)
})
}
}
struct RopeBuilder<'a> {