From 35a4ed908dcd338b0000f74b467f48fc1c0bafc6 Mon Sep 17 00:00:00 2001 From: Oleksiy Syvokon Date: Wed, 7 Jan 2026 15:30:36 +0200 Subject: [PATCH] Clamp the requested offset --- crates/ollama/src/ollama_edit_prediction_delegate.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ollama/src/ollama_edit_prediction_delegate.rs b/crates/ollama/src/ollama_edit_prediction_delegate.rs index e01ce909af7b067ec5dc93d5dc83a46e5006a1e3..fbc0b84c12784c706a994fed3e3830bd90d23554 100644 --- a/crates/ollama/src/ollama_edit_prediction_delegate.rs +++ b/crates/ollama/src/ollama_edit_prediction_delegate.rs @@ -251,9 +251,17 @@ impl EditPredictionDelegate for OllamaEditPredictionDelegate { } let edits: Arc<[(Range, Arc)]> = buffer.read_with(cx, |buffer, _cx| { + // Clamp the requested offset to the current buffer snapshot length. + // + // `anchor_after` ultimately asserts that the offset is within the rope bounds + // (in debug builds), and our `cursor_position` may be stale vs. the snapshot + // we used to compute `cursor_offset`. + let snapshot = buffer.snapshot(); + let clamped_cursor_offset = cursor_offset.min(snapshot.len()); + // Use anchor_after (Right bias) so the cursor stays before the completion text, // not at the end of it. This matches how Copilot handles edit predictions. - let position = buffer.anchor_after(cursor_offset); + let position = buffer.anchor_after(clamped_cursor_offset); vec![(position..position, completion_text.into())].into() })?; let edit_preview = buffer