zeta2: Build edit prediction prompt and process model output in client (#41870)
Release Notes: - N/A --------- Co-authored-by: Agus Zubiaga <agus@zed.dev> Co-authored-by: Ben Kunkle <ben@zed.dev> Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
co-authored by
Agus Zubiaga
Ben Kunkle
Piotr Osiewicz
parent
fb87972f44
commit
784fdcaee3
@@ -720,7 +720,7 @@ impl EditPreview {
|
||||
pub fn highlight_edits(
|
||||
&self,
|
||||
current_snapshot: &BufferSnapshot,
|
||||
edits: &[(Range<Anchor>, String)],
|
||||
edits: &[(Range<Anchor>, impl AsRef<str>)],
|
||||
include_deletions: bool,
|
||||
cx: &App,
|
||||
) -> HighlightedText {
|
||||
@@ -747,7 +747,8 @@ impl EditPreview {
|
||||
.end
|
||||
.bias_right(&self.old_snapshot)
|
||||
.to_offset(&self.applied_edits_snapshot);
|
||||
let edit_start_in_preview_snapshot = edit_new_end_in_preview_snapshot - edit_text.len();
|
||||
let edit_start_in_preview_snapshot =
|
||||
edit_new_end_in_preview_snapshot - edit_text.as_ref().len();
|
||||
|
||||
let unchanged_range_in_preview_snapshot =
|
||||
offset_in_preview_snapshot..edit_start_in_preview_snapshot;
|
||||
@@ -772,7 +773,7 @@ impl EditPreview {
|
||||
);
|
||||
}
|
||||
|
||||
if !edit_text.is_empty() {
|
||||
if !edit_text.as_ref().is_empty() {
|
||||
highlighted_text.add_text_from_buffer_range(
|
||||
edit_start_in_preview_snapshot..edit_new_end_in_preview_snapshot,
|
||||
&self.applied_edits_snapshot,
|
||||
@@ -796,7 +797,7 @@ impl EditPreview {
|
||||
highlighted_text.build()
|
||||
}
|
||||
|
||||
fn compute_visible_range(&self, edits: &[(Range<Anchor>, String)]) -> Option<Range<usize>> {
|
||||
fn compute_visible_range<T>(&self, edits: &[(Range<Anchor>, T)]) -> Option<Range<usize>> {
|
||||
let (first, _) = edits.first()?;
|
||||
let (last, _) = edits.last()?;
|
||||
|
||||
@@ -1130,7 +1131,7 @@ impl Buffer {
|
||||
|
||||
pub fn preview_edits(
|
||||
&self,
|
||||
edits: Arc<[(Range<Anchor>, String)]>,
|
||||
edits: Arc<[(Range<Anchor>, Arc<str>)]>,
|
||||
cx: &App,
|
||||
) -> Task<EditPreview> {
|
||||
let registry = self.language_registry();
|
||||
|
||||
@@ -3120,15 +3120,13 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
|
||||
.map(|(range, text)| {
|
||||
(
|
||||
buffer.anchor_before(range.start)..buffer.anchor_after(range.end),
|
||||
text.to_string(),
|
||||
text.into(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.collect::<Arc<[_]>>()
|
||||
});
|
||||
let edit_preview = buffer
|
||||
.read_with(cx, |buffer, cx| {
|
||||
buffer.preview_edits(edits.clone().into(), cx)
|
||||
})
|
||||
.read_with(cx, |buffer, cx| buffer.preview_edits(edits.clone(), cx))
|
||||
.await;
|
||||
let highlighted_edits = cx.read(|cx| {
|
||||
edit_preview.highlight_edits(&buffer.read(cx).snapshot(), &edits, include_deletions, cx)
|
||||
|
||||
Reference in New Issue
Block a user