From 5af15f7c9fc7ccffd24c1a9618834bd7fc163261 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Mon, 9 Feb 2026 17:48:15 -0600 Subject: [PATCH] Fix panic in zeta1 prompt parsing (#48822) Closes #48712 - [ ] Tests or screenshots needed? - [ ] Code Reviewed - [ ] Manual QA Release Notes: - Fixed a panic when parsing predictions made by zeta1 --- crates/edit_prediction/src/zeta1.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/edit_prediction/src/zeta1.rs b/crates/edit_prediction/src/zeta1.rs index 74c6cb568b26f19de21447d520d9569afa58b432..43d467950fd388fb5a771e8c101a005df57c6897 100644 --- a/crates/edit_prediction/src/zeta1.rs +++ b/crates/edit_prediction/src/zeta1.rs @@ -325,7 +325,8 @@ pub(crate) fn parse_edits( .map(|e| e.0.saturating_sub(1)) // -1 to exclude \n before marker .unwrap_or(content.strip_suffix("\n").unwrap_or(&content).len()); - let new_text = &content[content_start..content_end]; + // if there is a single newline between markers, content_start will be 1 more than content_end. .min ensures empty slice in that case + let new_text = &content[content_start.min(content_end)..content_end]; let old_text = snapshot .text_for_range(editable_range.clone()) @@ -717,4 +718,19 @@ mod tests { ```"#} ); } + + #[gpui::test] + fn test_parse_edits_empty_editable_region(cx: &mut App) { + let text = "fn foo() {\n let x = 42;\n}\n"; + let buffer = cx.new(|cx| Buffer::local(text, cx)); + let snapshot = buffer.read(cx).snapshot(); + + let output = "<|editable_region_start|>\n<|editable_region_end|>"; + let editable_range = 0..text.len(); + let edits = parse_edits(output, editable_range, &snapshot).unwrap(); + assert_eq!(edits.len(), 1); + let (range, new_text) = &edits[0]; + assert_eq!(range.to_offset(&snapshot), 0..text.len(),); + assert_eq!(new_text.as_ref(), ""); + } }