Opt into language-aware features when getting buffer chunks
We use chunks a lot to transform points and sync the various display maps, and always querying tree-sitter or the LSP diagnostics in those cases is unnecessarily expensive.
This commit is contained in:
parent
bd441723a0
commit
ab26a175a4
10 changed files with 91 additions and 53 deletions
|
@ -125,6 +125,7 @@ pub struct MultiBufferChunks<'a> {
|
|||
range: Range<usize>,
|
||||
excerpts: Cursor<'a, Excerpt, usize>,
|
||||
excerpt_chunks: Option<ExcerptChunks<'a>>,
|
||||
language_aware: bool,
|
||||
}
|
||||
|
||||
pub struct MultiBufferBytes<'a> {
|
||||
|
@ -1112,7 +1113,9 @@ impl Entity for MultiBuffer {
|
|||
|
||||
impl MultiBufferSnapshot {
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(0..self.len()).map(|chunk| chunk.text).collect()
|
||||
self.chunks(0..self.len(), false)
|
||||
.map(|chunk| chunk.text)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn reversed_chars_at<'a, T: ToOffset>(
|
||||
|
@ -1162,7 +1165,7 @@ impl MultiBufferSnapshot {
|
|||
&'a self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = &'a str> {
|
||||
self.chunks(range).map(|chunk| chunk.text)
|
||||
self.chunks(range, false).map(|chunk| chunk.text)
|
||||
}
|
||||
|
||||
pub fn is_line_blank(&self, row: u32) -> bool {
|
||||
|
@ -1320,12 +1323,17 @@ impl MultiBufferSnapshot {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn chunks<'a, T: ToOffset>(&'a self, range: Range<T>) -> MultiBufferChunks<'a> {
|
||||
pub fn chunks<'a, T: ToOffset>(
|
||||
&'a self,
|
||||
range: Range<T>,
|
||||
language_aware: bool,
|
||||
) -> MultiBufferChunks<'a> {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut chunks = MultiBufferChunks {
|
||||
range: range.clone(),
|
||||
excerpts: self.excerpts.cursor(),
|
||||
excerpt_chunks: None,
|
||||
language_aware: language_aware,
|
||||
};
|
||||
chunks.seek(range.start);
|
||||
chunks
|
||||
|
@ -2108,7 +2116,11 @@ impl Excerpt {
|
|||
}
|
||||
}
|
||||
|
||||
fn chunks_in_range<'a>(&'a self, range: Range<usize>) -> ExcerptChunks<'a> {
|
||||
fn chunks_in_range<'a>(
|
||||
&'a self,
|
||||
range: Range<usize>,
|
||||
language_aware: bool,
|
||||
) -> ExcerptChunks<'a> {
|
||||
let content_start = self.range.start.to_offset(&self.buffer);
|
||||
let chunks_start = content_start + range.start;
|
||||
let chunks_end = content_start + cmp::min(range.end, self.text_summary.bytes);
|
||||
|
@ -2122,7 +2134,7 @@ impl Excerpt {
|
|||
0
|
||||
};
|
||||
|
||||
let content_chunks = self.buffer.chunks(chunks_start..chunks_end);
|
||||
let content_chunks = self.buffer.chunks(chunks_start..chunks_end, language_aware);
|
||||
|
||||
ExcerptChunks {
|
||||
content_chunks,
|
||||
|
@ -2321,6 +2333,7 @@ impl<'a> MultiBufferChunks<'a> {
|
|||
if let Some(excerpt) = self.excerpts.item() {
|
||||
self.excerpt_chunks = Some(excerpt.chunks_in_range(
|
||||
self.range.start - self.excerpts.start()..self.range.end - self.excerpts.start(),
|
||||
self.language_aware,
|
||||
));
|
||||
} else {
|
||||
self.excerpt_chunks = None;
|
||||
|
@ -2340,8 +2353,10 @@ impl<'a> Iterator for MultiBufferChunks<'a> {
|
|||
} else {
|
||||
self.excerpts.next(&());
|
||||
let excerpt = self.excerpts.item()?;
|
||||
self.excerpt_chunks =
|
||||
Some(excerpt.chunks_in_range(0..self.range.end - self.excerpts.start()));
|
||||
self.excerpt_chunks = Some(excerpt.chunks_in_range(
|
||||
0..self.range.end - self.excerpts.start(),
|
||||
self.language_aware,
|
||||
));
|
||||
self.next()
|
||||
}
|
||||
}
|
||||
|
@ -3096,7 +3111,7 @@ mod tests {
|
|||
let mut buffer_point_utf16 = buffer_start_point_utf16;
|
||||
for ch in buffer
|
||||
.snapshot()
|
||||
.chunks(buffer_range.clone())
|
||||
.chunks(buffer_range.clone(), false)
|
||||
.flat_map(|c| c.text.chars())
|
||||
{
|
||||
for _ in 0..ch.len_utf8() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue