tab_map.rs

  1use super::{
  2    suggestion_map::{self, SuggestionChunks, SuggestionEdit, SuggestionPoint, SuggestionSnapshot},
  3    TextHighlights,
  4};
  5use crate::MultiBufferSnapshot;
  6use language::{Chunk, Point};
  7use parking_lot::Mutex;
  8use std::{cmp, mem, num::NonZeroU32, ops::Range};
  9use sum_tree::Bias;
 10
 11const MAX_EXPANSION_COLUMN: u32 = 256;
 12
 13pub struct TabMap(Mutex<TabSnapshot>);
 14
 15impl TabMap {
 16    pub fn new(input: SuggestionSnapshot, tab_size: NonZeroU32) -> (Self, TabSnapshot) {
 17        let snapshot = TabSnapshot {
 18            suggestion_snapshot: input,
 19            tab_size,
 20            max_expansion_column: MAX_EXPANSION_COLUMN,
 21            version: 0,
 22        };
 23        (Self(Mutex::new(snapshot.clone())), snapshot)
 24    }
 25
 26    #[cfg(test)]
 27    pub fn set_max_expansion_column(&self, column: u32) -> TabSnapshot {
 28        self.0.lock().max_expansion_column = column;
 29        self.0.lock().clone()
 30    }
 31
 32    pub fn sync(
 33        &self,
 34        suggestion_snapshot: SuggestionSnapshot,
 35        mut suggestion_edits: Vec<SuggestionEdit>,
 36        tab_size: NonZeroU32,
 37    ) -> (TabSnapshot, Vec<TabEdit>) {
 38        let mut old_snapshot = self.0.lock();
 39        let mut new_snapshot = TabSnapshot {
 40            suggestion_snapshot,
 41            tab_size,
 42            max_expansion_column: old_snapshot.max_expansion_column,
 43            version: old_snapshot.version,
 44        };
 45
 46        if old_snapshot.suggestion_snapshot.version != new_snapshot.suggestion_snapshot.version {
 47            new_snapshot.version += 1;
 48        }
 49
 50        let old_max_offset = old_snapshot.suggestion_snapshot.len();
 51        let mut tab_edits = Vec::with_capacity(suggestion_edits.len());
 52
 53        if old_snapshot.tab_size == new_snapshot.tab_size {
 54            for suggestion_edit in &mut suggestion_edits {
 55                let mut old_column = old_snapshot
 56                    .suggestion_snapshot
 57                    .to_point(suggestion_edit.old.end)
 58                    .column();
 59                let mut new_column = new_snapshot
 60                    .suggestion_snapshot
 61                    .to_point(suggestion_edit.new.end)
 62                    .column();
 63
 64                let mut delta = 0;
 65                let mut first_tab_ix = None;
 66                let mut last_tab_ix_with_changed_expansion = None;
 67                'outer: for chunk in old_snapshot.suggestion_snapshot.chunks(
 68                    suggestion_edit.old.end..old_max_offset,
 69                    false,
 70                    None,
 71                ) {
 72                    let patterns: &[_] = &['\t', '\n'];
 73                    for (ix, mat) in chunk.text.match_indices(patterns) {
 74                        match mat {
 75                            "\t" => {
 76                                if first_tab_ix.is_none() {
 77                                    first_tab_ix = Some(delta + ix);
 78                                }
 79
 80                                let old_column = old_column + ix as u32;
 81                                let new_column = new_column + ix as u32;
 82                                let was_expanded = old_column < old_snapshot.max_expansion_column;
 83                                let is_expanded = new_column < new_snapshot.max_expansion_column;
 84                                if was_expanded != is_expanded {
 85                                    last_tab_ix_with_changed_expansion = Some(delta + ix);
 86                                } else if !was_expanded && !is_expanded {
 87                                    break 'outer;
 88                                }
 89                            }
 90                            "\n" => break 'outer,
 91                            _ => unreachable!(),
 92                        }
 93                    }
 94
 95                    delta += chunk.text.len();
 96                    old_column += chunk.text.len() as u32;
 97                    new_column += chunk.text.len() as u32;
 98                    if old_column >= old_snapshot.max_expansion_column
 99                        && new_column >= new_snapshot.max_expansion_column
100                    {
101                        break;
102                    }
103                }
104
105                if let Some(tab_ix) = last_tab_ix_with_changed_expansion.or(first_tab_ix) {
106                    suggestion_edit.old.end.0 += tab_ix + 1;
107                    suggestion_edit.new.end.0 += tab_ix + 1;
108                }
109            }
110
111            let mut ix = 1;
112            while ix < suggestion_edits.len() {
113                let (prev_edits, next_edits) = suggestion_edits.split_at_mut(ix);
114                let prev_edit = prev_edits.last_mut().unwrap();
115                let edit = &next_edits[0];
116                if prev_edit.old.end >= edit.old.start {
117                    prev_edit.old.end = edit.old.end;
118                    prev_edit.new.end = edit.new.end;
119                    suggestion_edits.remove(ix);
120                } else {
121                    ix += 1;
122                }
123            }
124
125            for suggestion_edit in suggestion_edits {
126                let old_start = old_snapshot
127                    .suggestion_snapshot
128                    .to_point(suggestion_edit.old.start);
129                let old_end = old_snapshot
130                    .suggestion_snapshot
131                    .to_point(suggestion_edit.old.end);
132                let new_start = new_snapshot
133                    .suggestion_snapshot
134                    .to_point(suggestion_edit.new.start);
135                let new_end = new_snapshot
136                    .suggestion_snapshot
137                    .to_point(suggestion_edit.new.end);
138                tab_edits.push(TabEdit {
139                    old: old_snapshot.to_tab_point(old_start)..old_snapshot.to_tab_point(old_end),
140                    new: new_snapshot.to_tab_point(new_start)..new_snapshot.to_tab_point(new_end),
141                });
142            }
143        } else {
144            new_snapshot.version += 1;
145            tab_edits.push(TabEdit {
146                old: TabPoint::zero()..old_snapshot.max_point(),
147                new: TabPoint::zero()..new_snapshot.max_point(),
148            });
149        }
150
151        *old_snapshot = new_snapshot;
152        (old_snapshot.clone(), tab_edits)
153    }
154}
155
156#[derive(Clone)]
157pub struct TabSnapshot {
158    pub suggestion_snapshot: SuggestionSnapshot,
159    pub tab_size: NonZeroU32,
160    pub max_expansion_column: u32,
161    pub version: usize,
162}
163
164impl TabSnapshot {
165    pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot {
166        self.suggestion_snapshot.buffer_snapshot()
167    }
168
169    pub fn line_len(&self, row: u32) -> u32 {
170        let max_point = self.max_point();
171        if row < max_point.row() {
172            self.to_tab_point(SuggestionPoint::new(
173                row,
174                self.suggestion_snapshot.line_len(row),
175            ))
176            .0
177            .column
178        } else {
179            max_point.column()
180        }
181    }
182
183    pub fn text_summary(&self) -> TextSummary {
184        self.text_summary_for_range(TabPoint::zero()..self.max_point())
185    }
186
187    pub fn text_summary_for_range(&self, range: Range<TabPoint>) -> TextSummary {
188        let input_start = self.to_suggestion_point(range.start, Bias::Left).0;
189        let input_end = self.to_suggestion_point(range.end, Bias::Right).0;
190        let input_summary = self
191            .suggestion_snapshot
192            .text_summary_for_range(input_start..input_end);
193
194        let mut first_line_chars = 0;
195        let line_end = if range.start.row() == range.end.row() {
196            range.end
197        } else {
198            self.max_point()
199        };
200        for c in self
201            .chunks(range.start..line_end, false, None)
202            .flat_map(|chunk| chunk.text.chars())
203        {
204            if c == '\n' {
205                break;
206            }
207            first_line_chars += 1;
208        }
209
210        let mut last_line_chars = 0;
211        if range.start.row() == range.end.row() {
212            last_line_chars = first_line_chars;
213        } else {
214            for _ in self
215                .chunks(TabPoint::new(range.end.row(), 0)..range.end, false, None)
216                .flat_map(|chunk| chunk.text.chars())
217            {
218                last_line_chars += 1;
219            }
220        }
221
222        TextSummary {
223            lines: range.end.0 - range.start.0,
224            first_line_chars,
225            last_line_chars,
226            longest_row: input_summary.longest_row,
227            longest_row_chars: input_summary.longest_row_chars,
228        }
229    }
230
231    pub fn chunks<'a>(
232        &'a self,
233        range: Range<TabPoint>,
234        language_aware: bool,
235        text_highlights: Option<&'a TextHighlights>,
236    ) -> TabChunks<'a> {
237        let (input_start, expanded_char_column, to_next_stop) =
238            self.to_suggestion_point(range.start, Bias::Left);
239        let input_column = input_start.column();
240        let input_start = self.suggestion_snapshot.to_offset(input_start);
241        let input_end = self
242            .suggestion_snapshot
243            .to_offset(self.to_suggestion_point(range.end, Bias::Right).0);
244        let to_next_stop = if range.start.0 + Point::new(0, to_next_stop) > range.end.0 {
245            range.end.column() - range.start.column()
246        } else {
247            to_next_stop
248        };
249
250        TabChunks {
251            suggestion_chunks: self.suggestion_snapshot.chunks(
252                input_start..input_end,
253                language_aware,
254                text_highlights,
255            ),
256            input_column,
257            column: expanded_char_column,
258            max_expansion_column: self.max_expansion_column,
259            output_position: range.start.0,
260            max_output_position: range.end.0,
261            tab_size: self.tab_size,
262            chunk: Chunk {
263                text: &SPACES[0..(to_next_stop as usize)],
264                ..Default::default()
265            },
266            inside_leading_tab: to_next_stop > 0,
267        }
268    }
269
270    pub fn buffer_rows(&self, row: u32) -> suggestion_map::SuggestionBufferRows {
271        self.suggestion_snapshot.buffer_rows(row)
272    }
273
274    #[cfg(test)]
275    pub fn text(&self) -> String {
276        self.chunks(TabPoint::zero()..self.max_point(), false, None)
277            .map(|chunk| chunk.text)
278            .collect()
279    }
280
281    pub fn max_point(&self) -> TabPoint {
282        self.to_tab_point(self.suggestion_snapshot.max_point())
283    }
284
285    pub fn clip_point(&self, point: TabPoint, bias: Bias) -> TabPoint {
286        self.to_tab_point(
287            self.suggestion_snapshot
288                .clip_point(self.to_suggestion_point(point, bias).0, bias),
289        )
290    }
291
292    pub fn to_tab_point(&self, input: SuggestionPoint) -> TabPoint {
293        let chars = self
294            .suggestion_snapshot
295            .chars_at(SuggestionPoint::new(input.row(), 0));
296        let expanded = self.expand_tabs(chars, input.column());
297        TabPoint::new(input.row(), expanded)
298    }
299
300    pub fn to_suggestion_point(&self, output: TabPoint, bias: Bias) -> (SuggestionPoint, u32, u32) {
301        let chars = self
302            .suggestion_snapshot
303            .chars_at(SuggestionPoint::new(output.row(), 0));
304        let expanded = output.column();
305        let (collapsed, expanded_char_column, to_next_stop) =
306            self.collapse_tabs(chars, expanded, bias);
307        (
308            SuggestionPoint::new(output.row(), collapsed as u32),
309            expanded_char_column,
310            to_next_stop,
311        )
312    }
313
314    pub fn make_tab_point(&self, point: Point, bias: Bias) -> TabPoint {
315        let fold_point = self
316            .suggestion_snapshot
317            .fold_snapshot
318            .to_fold_point(point, bias);
319        let suggestion_point = self.suggestion_snapshot.to_suggestion_point(fold_point);
320        self.to_tab_point(suggestion_point)
321    }
322
323    pub fn to_point(&self, point: TabPoint, bias: Bias) -> Point {
324        let suggestion_point = self.to_suggestion_point(point, bias).0;
325        let fold_point = self.suggestion_snapshot.to_fold_point(suggestion_point);
326        fold_point.to_buffer_point(&self.suggestion_snapshot.fold_snapshot)
327    }
328
329    fn expand_tabs(&self, chars: impl Iterator<Item = char>, column: u32) -> u32 {
330        let tab_size = self.tab_size.get();
331
332        let mut expanded_chars = 0;
333        let mut expanded_bytes = 0;
334        let mut collapsed_bytes = 0;
335        let end_column = column.min(self.max_expansion_column);
336        for c in chars {
337            if collapsed_bytes >= end_column {
338                break;
339            }
340            if c == '\t' {
341                let tab_len = tab_size - expanded_chars % tab_size;
342                expanded_bytes += tab_len;
343                expanded_chars += tab_len;
344            } else {
345                expanded_bytes += c.len_utf8() as u32;
346                expanded_chars += 1;
347            }
348            collapsed_bytes += c.len_utf8() as u32;
349        }
350        expanded_bytes + column.saturating_sub(collapsed_bytes)
351    }
352
353    fn collapse_tabs(
354        &self,
355        chars: impl Iterator<Item = char>,
356        column: u32,
357        bias: Bias,
358    ) -> (u32, u32, u32) {
359        let tab_size = self.tab_size.get();
360
361        let mut expanded_bytes = 0;
362        let mut expanded_chars = 0;
363        let mut collapsed_bytes = 0;
364        for c in chars {
365            if expanded_bytes >= column {
366                break;
367            }
368            if collapsed_bytes >= self.max_expansion_column {
369                break;
370            }
371
372            if c == '\t' {
373                let tab_len = tab_size - (expanded_chars % tab_size);
374                expanded_chars += tab_len;
375                expanded_bytes += tab_len;
376                if expanded_bytes > column {
377                    expanded_chars -= expanded_bytes - column;
378                    return match bias {
379                        Bias::Left => (collapsed_bytes, expanded_chars, expanded_bytes - column),
380                        Bias::Right => (collapsed_bytes + 1, expanded_chars, 0),
381                    };
382                }
383            } else {
384                expanded_chars += 1;
385                expanded_bytes += c.len_utf8() as u32;
386            }
387
388            if expanded_bytes > column && matches!(bias, Bias::Left) {
389                expanded_chars -= 1;
390                break;
391            }
392
393            collapsed_bytes += c.len_utf8() as u32;
394        }
395        (
396            collapsed_bytes + column.saturating_sub(expanded_bytes),
397            expanded_chars,
398            0,
399        )
400    }
401}
402
403#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
404pub struct TabPoint(pub Point);
405
406impl TabPoint {
407    pub fn new(row: u32, column: u32) -> Self {
408        Self(Point::new(row, column))
409    }
410
411    pub fn zero() -> Self {
412        Self::new(0, 0)
413    }
414
415    pub fn row(self) -> u32 {
416        self.0.row
417    }
418
419    pub fn column(self) -> u32 {
420        self.0.column
421    }
422}
423
424impl From<Point> for TabPoint {
425    fn from(point: Point) -> Self {
426        Self(point)
427    }
428}
429
430pub type TabEdit = text::Edit<TabPoint>;
431
432#[derive(Clone, Debug, Default, Eq, PartialEq)]
433pub struct TextSummary {
434    pub lines: Point,
435    pub first_line_chars: u32,
436    pub last_line_chars: u32,
437    pub longest_row: u32,
438    pub longest_row_chars: u32,
439}
440
441impl<'a> From<&'a str> for TextSummary {
442    fn from(text: &'a str) -> Self {
443        let sum = text::TextSummary::from(text);
444
445        TextSummary {
446            lines: sum.lines,
447            first_line_chars: sum.first_line_chars,
448            last_line_chars: sum.last_line_chars,
449            longest_row: sum.longest_row,
450            longest_row_chars: sum.longest_row_chars,
451        }
452    }
453}
454
455impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
456    fn add_assign(&mut self, other: &'a Self) {
457        let joined_chars = self.last_line_chars + other.first_line_chars;
458        if joined_chars > self.longest_row_chars {
459            self.longest_row = self.lines.row;
460            self.longest_row_chars = joined_chars;
461        }
462        if other.longest_row_chars > self.longest_row_chars {
463            self.longest_row = self.lines.row + other.longest_row;
464            self.longest_row_chars = other.longest_row_chars;
465        }
466
467        if self.lines.row == 0 {
468            self.first_line_chars += other.first_line_chars;
469        }
470
471        if other.lines.row == 0 {
472            self.last_line_chars += other.first_line_chars;
473        } else {
474            self.last_line_chars = other.last_line_chars;
475        }
476
477        self.lines += &other.lines;
478    }
479}
480
481// Handles a tab width <= 16
482const SPACES: &str = "                ";
483
484pub struct TabChunks<'a> {
485    suggestion_chunks: SuggestionChunks<'a>,
486    chunk: Chunk<'a>,
487    column: u32,
488    max_expansion_column: u32,
489    output_position: Point,
490    input_column: u32,
491    max_output_position: Point,
492    tab_size: NonZeroU32,
493    inside_leading_tab: bool,
494}
495
496impl<'a> Iterator for TabChunks<'a> {
497    type Item = Chunk<'a>;
498
499    fn next(&mut self) -> Option<Self::Item> {
500        if self.chunk.text.is_empty() {
501            if let Some(chunk) = self.suggestion_chunks.next() {
502                self.chunk = chunk;
503                if self.inside_leading_tab {
504                    self.chunk.text = &self.chunk.text[1..];
505                    self.inside_leading_tab = false;
506                    self.input_column += 1;
507                }
508            } else {
509                return None;
510            }
511        }
512
513        for (ix, c) in self.chunk.text.char_indices() {
514            match c {
515                '\t' => {
516                    if ix > 0 {
517                        let (prefix, suffix) = self.chunk.text.split_at(ix);
518                        self.chunk.text = suffix;
519                        return Some(Chunk {
520                            text: prefix,
521                            ..self.chunk
522                        });
523                    } else {
524                        self.chunk.text = &self.chunk.text[1..];
525                        let tab_size = if self.input_column < self.max_expansion_column {
526                            self.tab_size.get() as u32
527                        } else {
528                            1
529                        };
530                        let mut len = tab_size - self.column % tab_size;
531                        let next_output_position = cmp::min(
532                            self.output_position + Point::new(0, len),
533                            self.max_output_position,
534                        );
535                        len = next_output_position.column - self.output_position.column;
536                        self.column += len;
537                        self.input_column += 1;
538                        self.output_position = next_output_position;
539                        return Some(Chunk {
540                            text: &SPACES[..len as usize],
541                            ..self.chunk
542                        });
543                    }
544                }
545                '\n' => {
546                    self.column = 0;
547                    self.input_column = 0;
548                    self.output_position += Point::new(1, 0);
549                }
550                _ => {
551                    self.column += 1;
552                    if !self.inside_leading_tab {
553                        self.input_column += c.len_utf8() as u32;
554                    }
555                    self.output_position.column += c.len_utf8() as u32;
556                }
557            }
558        }
559
560        Some(mem::take(&mut self.chunk))
561    }
562}
563
564#[cfg(test)]
565mod tests {
566    use super::*;
567    use crate::{
568        display_map::{fold_map::FoldMap, suggestion_map::SuggestionMap},
569        MultiBuffer,
570    };
571    use rand::{prelude::StdRng, Rng};
572
573    #[gpui::test]
574    fn test_expand_tabs(cx: &mut gpui::MutableAppContext) {
575        let buffer = MultiBuffer::build_simple("", cx);
576        let buffer_snapshot = buffer.read(cx).snapshot(cx);
577        let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
578        let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
579        let (_, tab_snapshot) = TabMap::new(suggestion_snapshot, 4.try_into().unwrap());
580
581        assert_eq!(tab_snapshot.expand_tabs("\t".chars(), 0), 0);
582        assert_eq!(tab_snapshot.expand_tabs("\t".chars(), 1), 4);
583        assert_eq!(tab_snapshot.expand_tabs("\ta".chars(), 2), 5);
584    }
585
586    #[gpui::test]
587    fn test_long_lines(cx: &mut gpui::MutableAppContext) {
588        let max_expansion_column = 12;
589        let input = "A\tBC\tDEF\tG\tHI\tJ\tK\tL\tM";
590        let output = "A   BC  DEF G   HI J K L M";
591
592        let buffer = MultiBuffer::build_simple(input, cx);
593        let buffer_snapshot = buffer.read(cx).snapshot(cx);
594        let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
595        let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
596        let (_, mut tab_snapshot) = TabMap::new(suggestion_snapshot, 4.try_into().unwrap());
597
598        tab_snapshot.max_expansion_column = max_expansion_column;
599        assert_eq!(tab_snapshot.text(), output);
600
601        for (ix, c) in input.char_indices() {
602            assert_eq!(
603                tab_snapshot
604                    .chunks(
605                        TabPoint::new(0, ix as u32)..tab_snapshot.max_point(),
606                        false,
607                        None
608                    )
609                    .map(|c| c.text)
610                    .collect::<String>(),
611                &output[ix..],
612                "text from index {ix}"
613            );
614
615            if c != '\t' {
616                let input_point = Point::new(0, ix as u32);
617                let output_point = Point::new(0, output.find(c).unwrap() as u32);
618                assert_eq!(
619                    tab_snapshot.to_tab_point(SuggestionPoint(input_point)),
620                    TabPoint(output_point),
621                    "to_tab_point({input_point:?})"
622                );
623                assert_eq!(
624                    tab_snapshot
625                        .to_suggestion_point(TabPoint(output_point), Bias::Left)
626                        .0,
627                    SuggestionPoint(input_point),
628                    "to_suggestion_point({output_point:?})"
629                );
630            }
631        }
632    }
633
634    #[gpui::test]
635    fn test_long_lines_with_character_spanning_max_expansion_column(
636        cx: &mut gpui::MutableAppContext,
637    ) {
638        let max_expansion_column = 8;
639        let input = "abcdefg⋯hij";
640
641        let buffer = MultiBuffer::build_simple(input, cx);
642        let buffer_snapshot = buffer.read(cx).snapshot(cx);
643        let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
644        let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
645        let (_, mut tab_snapshot) = TabMap::new(suggestion_snapshot, 4.try_into().unwrap());
646
647        tab_snapshot.max_expansion_column = max_expansion_column;
648        assert_eq!(tab_snapshot.text(), input);
649    }
650
651    #[gpui::test(iterations = 100)]
652    fn test_random_tabs(cx: &mut gpui::MutableAppContext, mut rng: StdRng) {
653        let tab_size = NonZeroU32::new(rng.gen_range(1..=4)).unwrap();
654        let len = rng.gen_range(0..30);
655        let buffer = if rng.gen() {
656            let text = util::RandomCharIter::new(&mut rng)
657                .take(len)
658                .collect::<String>();
659            MultiBuffer::build_simple(&text, cx)
660        } else {
661            MultiBuffer::build_random(&mut rng, cx)
662        };
663        let buffer_snapshot = buffer.read(cx).snapshot(cx);
664        log::info!("Buffer text: {:?}", buffer_snapshot.text());
665
666        let (mut fold_map, _) = FoldMap::new(buffer_snapshot.clone());
667        fold_map.randomly_mutate(&mut rng);
668        let (fold_snapshot, _) = fold_map.read(buffer_snapshot, vec![]);
669        log::info!("FoldMap text: {:?}", fold_snapshot.text());
670        let (suggestion_map, _) = SuggestionMap::new(fold_snapshot);
671        let (suggestion_snapshot, _) = suggestion_map.randomly_mutate(&mut rng);
672        log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
673
674        let (tab_map, _) = TabMap::new(suggestion_snapshot.clone(), tab_size);
675        let tabs_snapshot = tab_map.set_max_expansion_column(32);
676
677        let text = text::Rope::from(tabs_snapshot.text().as_str());
678        log::info!(
679            "TabMap text (tab size: {}): {:?}",
680            tab_size,
681            tabs_snapshot.text(),
682        );
683
684        for _ in 0..5 {
685            let end_row = rng.gen_range(0..=text.max_point().row);
686            let end_column = rng.gen_range(0..=text.line_len(end_row));
687            let mut end = TabPoint(text.clip_point(Point::new(end_row, end_column), Bias::Right));
688            let start_row = rng.gen_range(0..=text.max_point().row);
689            let start_column = rng.gen_range(0..=text.line_len(start_row));
690            let mut start =
691                TabPoint(text.clip_point(Point::new(start_row, start_column), Bias::Left));
692            if start > end {
693                mem::swap(&mut start, &mut end);
694            }
695
696            let expected_text = text
697                .chunks_in_range(text.point_to_offset(start.0)..text.point_to_offset(end.0))
698                .collect::<String>();
699            let expected_summary = TextSummary::from(expected_text.as_str());
700            assert_eq!(
701                tabs_snapshot
702                    .chunks(start..end, false, None)
703                    .map(|c| c.text)
704                    .collect::<String>(),
705                expected_text,
706                "chunks({:?}..{:?})",
707                start,
708                end
709            );
710
711            let mut actual_summary = tabs_snapshot.text_summary_for_range(start..end);
712            if tab_size.get() > 1 && suggestion_snapshot.text().contains('\t') {
713                actual_summary.longest_row = expected_summary.longest_row;
714                actual_summary.longest_row_chars = expected_summary.longest_row_chars;
715            }
716            assert_eq!(actual_summary, expected_summary);
717        }
718
719        for row in 0..=text.max_point().row {
720            assert_eq!(
721                tabs_snapshot.line_len(row),
722                text.line_len(row),
723                "line_len({row})"
724            );
725        }
726    }
727}