@@ -2834,8 +2834,7 @@ impl EditorElement {
return None;
}
- let (text, highlights) =
- inline_completion_popover_text(edit_start, editor_snapshot, edits, cx);
+ let (text, highlights) = inline_completion_popover_text(editor_snapshot, edits, cx);
let longest_row =
editor_snapshot.longest_row_in_range(edit_start.row()..edit_end.row() + 1);
@@ -4300,11 +4299,17 @@ impl EditorElement {
}
fn inline_completion_popover_text(
- edit_start: DisplayPoint,
editor_snapshot: &EditorSnapshot,
edits: &Vec<(Range<Anchor>, String)>,
cx: &WindowContext,
) -> (String, Vec<(Range<usize>, HighlightStyle)>) {
+ let edit_start = edits
+ .first()
+ .unwrap()
+ .0
+ .start
+ .to_display_point(editor_snapshot);
+
let mut text = String::new();
let mut offset = DisplayPoint::new(edit_start.row(), 0).to_offset(editor_snapshot, Bias::Left);
let mut highlights = Vec::new();
@@ -4329,6 +4334,22 @@ fn inline_completion_popover_text(
},
));
}
+
+ let edit_end = edits
+ .last()
+ .unwrap()
+ .0
+ .end
+ .to_display_point(editor_snapshot);
+ let end_of_line = DisplayPoint::new(edit_end.row(), editor_snapshot.line_len(edit_end.row()))
+ .to_offset(editor_snapshot, Bias::Right);
+ text.extend(
+ editor_snapshot
+ .buffer_snapshot
+ .chunks(offset..end_of_line, false)
+ .map(|chunk| chunk.text),
+ );
+
(text, highlights)
}
@@ -7097,13 +7118,11 @@ mod tests {
let snapshot = editor.snapshot(cx);
let edit_range = snapshot.buffer_snapshot.anchor_after(Point::new(0, 6))
..snapshot.buffer_snapshot.anchor_before(Point::new(0, 6));
- let edit_start = DisplayPoint::new(DisplayRow(0), 6);
let edits = vec![(edit_range, " beautiful".to_string())];
- let (text, highlights) =
- inline_completion_popover_text(edit_start, &snapshot, &edits, cx);
+ let (text, highlights) = inline_completion_popover_text(&snapshot, &edits, cx);
- assert_eq!(text, "Hello, beautiful");
+ assert_eq!(text, "Hello, beautiful world!");
assert_eq!(highlights.len(), 1);
assert_eq!(highlights[0].0, 6..16);
assert_eq!(
@@ -7125,17 +7144,15 @@ mod tests {
window
.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
- let edit_start = DisplayPoint::new(DisplayRow(0), 0);
let edits = vec![(
snapshot.buffer_snapshot.anchor_after(Point::new(0, 0))
..snapshot.buffer_snapshot.anchor_before(Point::new(0, 4)),
"That".to_string(),
)];
- let (text, highlights) =
- inline_completion_popover_text(edit_start, &snapshot, &edits, cx);
+ let (text, highlights) = inline_completion_popover_text(&snapshot, &edits, cx);
- assert_eq!(text, "That");
+ assert_eq!(text, "That is a test.");
assert_eq!(highlights.len(), 1);
assert_eq!(highlights[0].0, 0..4);
assert_eq!(
@@ -7157,7 +7174,6 @@ mod tests {
window
.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
- let edit_start = DisplayPoint::new(DisplayRow(0), 0);
let edits = vec![
(
snapshot.buffer_snapshot.anchor_after(Point::new(0, 0))
@@ -7166,15 +7182,14 @@ mod tests {
),
(
snapshot.buffer_snapshot.anchor_after(Point::new(0, 12))
- ..snapshot.buffer_snapshot.anchor_before(Point::new(0, 13)),
+ ..snapshot.buffer_snapshot.anchor_before(Point::new(0, 12)),
" and universe".into(),
),
];
- let (text, highlights) =
- inline_completion_popover_text(edit_start, &snapshot, &edits, cx);
+ let (text, highlights) = inline_completion_popover_text(&snapshot, &edits, cx);
- assert_eq!(text, "Greetings, world and universe");
+ assert_eq!(text, "Greetings, world and universe!");
assert_eq!(highlights.len(), 2);
assert_eq!(highlights[0].0, 0..9);
assert_eq!(highlights[1].0, 16..29);
@@ -7204,7 +7219,6 @@ mod tests {
window
.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
- let edit_start = DisplayPoint::new(DisplayRow(1), 0);
let edits = vec![
(
snapshot.buffer_snapshot.anchor_before(Point::new(1, 7))
@@ -7223,10 +7237,9 @@ mod tests {
),
];
- let (text, highlights) =
- inline_completion_popover_text(edit_start, &snapshot, &edits, cx);
+ let (text, highlights) = inline_completion_popover_text(&snapshot, &edits, cx);
- assert_eq!(text, "Second modified\nNew third line\nFourth updated");
+ assert_eq!(text, "Second modified\nNew third line\nFourth updated line");
assert_eq!(highlights.len(), 3);
assert_eq!(highlights[0].0, 7..15); // "modified"
assert_eq!(highlights[1].0, 16..30); // "New third line"