From 24bc9fd0a001f13c9cc5ece44a0fab8c059ab332 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 12 May 2025 14:39:06 +0200 Subject: [PATCH] Fix completions in debugger panel (#30545) Release Notes: - N/A --- .../src/session/running/console.rs | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs index 33cbd2d9970503f828bd550a1ce51eb204e277fd..7550dcb25643bb7811d2c60bf5ccd64c46541535 100644 --- a/crates/debugger_ui/src/session/running/console.rs +++ b/crates/debugger_ui/src/session/running/console.rs @@ -5,7 +5,7 @@ use super::{ use anyhow::Result; use collections::HashMap; use dap::OutputEvent; -use editor::{CompletionProvider, Editor, EditorElement, EditorStyle, ExcerptId}; +use editor::{Bias, CompletionProvider, Editor, EditorElement, EditorStyle, ExcerptId}; use fuzzy::StringMatchCandidate; use gpui::{ Context, Entity, FocusHandle, Focusable, Render, Subscription, Task, TextStyle, WeakEntity, @@ -401,28 +401,21 @@ impl ConsoleQueryBarCompletionProvider { .as_ref() .unwrap_or(&completion.label) .to_owned(); - let mut word_bytes_length = 0; - for chunk in snapshot - .reversed_chunks_in_range(language::Anchor::MIN..buffer_position) - { - let mut processed_bytes = 0; - if let Some(_) = chunk.chars().rfind(|c| { - let is_whitespace = c.is_whitespace(); - if !is_whitespace { - processed_bytes += c.len_utf8(); - } - - is_whitespace - }) { - word_bytes_length += processed_bytes; + let buffer_text = snapshot.text(); + let buffer_bytes = buffer_text.as_bytes(); + let new_bytes = new_text.as_bytes(); + + let mut prefix_len = 0; + for i in (0..new_bytes.len()).rev() { + if buffer_bytes.ends_with(&new_bytes[0..i]) { + prefix_len = i; break; - } else { - word_bytes_length += chunk.len(); } } let buffer_offset = buffer_position.to_offset(&snapshot); - let start = buffer_offset - word_bytes_length; + let start = buffer_offset - prefix_len; + let start = snapshot.clip_offset(start, Bias::Left); let start = snapshot.anchor_before(start); let replace_range = start..buffer_position;