Skip to content

Commit 1f8b606

Browse files
committed
refactor: Return Option from splice_lines
1 parent 3c3b623 commit 1f8b606

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/renderer/render.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ fn emit_suggestion_default(
14541454

14551455
let buffer_offset = buffer.num_lines();
14561456
let mut row_num = buffer_offset + usize::from(!matches_previous_suggestion);
1457-
for (complete, parts, highlights) in &suggestions {
1457+
if let Some((complete, parts, highlights)) = suggestions {
14581458
let has_deletion = parts
14591459
.iter()
14601460
.any(|p| p.is_deletion(sm) || p.is_destructive_replacement(sm));
@@ -1636,7 +1636,7 @@ fn emit_suggestion_default(
16361636
renderer,
16371637
buffer,
16381638
&mut row_num,
1639-
highlight_parts,
1639+
&highlight_parts,
16401640
line_pos + line_start.line,
16411641
line,
16421642
show_code_change,
@@ -1850,7 +1850,6 @@ fn emit_suggestion_default(
18501850
} else {
18511851
draw_col_separator_end(renderer, buffer, row, max_line_num_len + 1);
18521852
}
1853-
row_num = row + 1;
18541853
}
18551854
}
18561855
}

src/renderer/source_map.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,7 @@ impl<'a> SourceMap<'a> {
371371
&'b self,
372372
mut patches: Vec<Patch<'b>>,
373373
fold: bool,
374-
) -> Vec<(
375-
String,
376-
Vec<TrimmedPatch<'b>>,
377-
Vec<Vec<SubstitutionHighlight>>,
378-
)> {
374+
) -> Option<SplicedLines<'b>> {
379375
fn push_trailing(
380376
buf: &mut String,
381377
line_opt: Option<&str>,
@@ -432,12 +428,8 @@ impl<'a> SourceMap<'a> {
432428

433429
// Find the bounding span.
434430
let (lo, hi) = if fold {
435-
let Some(lo) = patches.iter().map(|p| p.span.start).min() else {
436-
return Vec::new();
437-
};
438-
let Some(hi) = patches.iter().map(|p| p.span.end).max() else {
439-
return Vec::new();
440-
};
431+
let lo = patches.iter().map(|p| p.span.start).min()?;
432+
let hi = patches.iter().map(|p| p.span.end).max()?;
441433
(lo, hi)
442434
} else {
443435
(0, source_len)
@@ -561,9 +553,9 @@ impl<'a> SourceMap<'a> {
561553
buf.pop();
562554
}
563555
if highlights.iter().all(|parts| parts.is_empty()) {
564-
Vec::new()
556+
None
565557
} else {
566-
vec![(buf, trimmed_patches, highlights)]
558+
Some((buf, trimmed_patches, highlights))
567559
}
568560
}
569561
}
@@ -720,6 +712,12 @@ impl<'a> Iterator for CursorLines<'a> {
720712
}
721713
}
722714

715+
pub(crate) type SplicedLines<'a> = (
716+
String,
717+
Vec<TrimmedPatch<'a>>,
718+
Vec<Vec<SubstitutionHighlight>>,
719+
);
720+
723721
/// Used to translate between `Span`s and byte positions within a single output line in highlighted
724722
/// code of structured suggestions.
725723
#[derive(Debug, Clone, Copy)]

0 commit comments

Comments
 (0)