Introduce staff-only inline completion provider (#21739)
Release Notes: - N/A --------- Co-authored-by: Thorsten Ball <mrnugget@gmail.com> Co-authored-by: Bennet <bennet@zed.dev> Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
parent
39e8944dcc
commit
77b8296fbb
39 changed files with 2890 additions and 356 deletions
|
@ -1339,6 +1339,57 @@ impl BlockSnapshot {
|
|||
self.transforms.summary().longest_row
|
||||
}
|
||||
|
||||
pub fn longest_row_in_range(&self, range: Range<BlockRow>) -> BlockRow {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
cursor.seek(&range.start, Bias::Right, &());
|
||||
|
||||
let mut longest_row = range.start;
|
||||
let mut longest_row_chars = 0;
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_none() {
|
||||
let (output_start, input_start) = cursor.start();
|
||||
let overshoot = range.start.0 - output_start.0;
|
||||
let wrap_start_row = input_start.0 + overshoot;
|
||||
let wrap_end_row = cmp::min(
|
||||
input_start.0 + (range.end.0 - output_start.0),
|
||||
cursor.end(&()).1 .0,
|
||||
);
|
||||
let summary = self
|
||||
.wrap_snapshot
|
||||
.text_summary_for_range(wrap_start_row..wrap_end_row);
|
||||
longest_row = BlockRow(range.start.0 + summary.longest_row);
|
||||
longest_row_chars = summary.longest_row_chars;
|
||||
}
|
||||
cursor.next(&());
|
||||
}
|
||||
|
||||
let cursor_start_row = cursor.start().0;
|
||||
if range.end > cursor_start_row {
|
||||
let summary = cursor.summary::<_, TransformSummary>(&range.end, Bias::Right, &());
|
||||
if summary.longest_row_chars > longest_row_chars {
|
||||
longest_row = BlockRow(cursor_start_row.0 + summary.longest_row);
|
||||
longest_row_chars = summary.longest_row_chars;
|
||||
}
|
||||
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_none() {
|
||||
let (output_start, input_start) = cursor.start();
|
||||
let overshoot = range.end.0 - output_start.0;
|
||||
let wrap_start_row = input_start.0;
|
||||
let wrap_end_row = input_start.0 + overshoot;
|
||||
let summary = self
|
||||
.wrap_snapshot
|
||||
.text_summary_for_range(wrap_start_row..wrap_end_row);
|
||||
if summary.longest_row_chars > longest_row_chars {
|
||||
longest_row = BlockRow(output_start.0 + summary.longest_row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
longest_row
|
||||
}
|
||||
|
||||
pub(super) fn line_len(&self, row: BlockRow) -> u32 {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
cursor.seek(&BlockRow(row.0), Bias::Right, &());
|
||||
|
@ -2705,6 +2756,40 @@ mod tests {
|
|||
longest_line_len,
|
||||
);
|
||||
|
||||
for _ in 0..10 {
|
||||
let end_row = rng.gen_range(1..=expected_lines.len());
|
||||
let start_row = rng.gen_range(0..end_row);
|
||||
|
||||
let mut expected_longest_rows_in_range = vec![];
|
||||
let mut longest_line_len_in_range = 0;
|
||||
|
||||
let mut row = start_row as u32;
|
||||
for line in &expected_lines[start_row..end_row] {
|
||||
let line_char_count = line.chars().count() as isize;
|
||||
match line_char_count.cmp(&longest_line_len_in_range) {
|
||||
Ordering::Less => {}
|
||||
Ordering::Equal => expected_longest_rows_in_range.push(row),
|
||||
Ordering::Greater => {
|
||||
longest_line_len_in_range = line_char_count;
|
||||
expected_longest_rows_in_range.clear();
|
||||
expected_longest_rows_in_range.push(row);
|
||||
}
|
||||
}
|
||||
row += 1;
|
||||
}
|
||||
|
||||
let longest_row_in_range = blocks_snapshot
|
||||
.longest_row_in_range(BlockRow(start_row as u32)..BlockRow(end_row as u32));
|
||||
assert!(
|
||||
expected_longest_rows_in_range.contains(&longest_row_in_range.0),
|
||||
"incorrect longest row {} in range {:?}. expected {:?} with length {}",
|
||||
longest_row,
|
||||
start_row..end_row,
|
||||
expected_longest_rows_in_range,
|
||||
longest_line_len_in_range,
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure that conversion between block points and wrap points is stable.
|
||||
for row in 0..=blocks_snapshot.wrap_snapshot.max_point().row() {
|
||||
let wrap_point = WrapPoint::new(row, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue