Fix word completions clobbering the text after the cursor (#32010)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-06-03 13:37:26 -06:00 committed by GitHub
parent d8195a8fd7
commit 5ae8c4cf09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5106,14 +5106,15 @@ impl Editor {
trigger_kind,
};
let (replace_range, word_kind) = buffer_snapshot.surrounding_word(buffer_position);
let (replace_range, word_to_exclude) = if word_kind == Some(CharKind::Word) {
let (word_replace_range, word_to_exclude) = if let (word_range, Some(CharKind::Word)) =
buffer_snapshot.surrounding_word(buffer_position)
{
let word_to_exclude = buffer_snapshot
.text_for_range(replace_range.clone())
.text_for_range(word_range.clone())
.collect::<String>();
(
buffer_snapshot.anchor_before(replace_range.start)
..buffer_snapshot.anchor_after(replace_range.end),
buffer_snapshot.anchor_before(word_range.start)
..buffer_snapshot.anchor_after(buffer_position),
Some(word_to_exclude),
)
} else {
@ -5221,7 +5222,7 @@ impl Editor {
words.remove(&lsp_completion.new_text);
}
completions.extend(words.into_iter().map(|(word, word_range)| Completion {
replace_range: replace_range.clone(),
replace_range: word_replace_range.clone(),
new_text: word.clone(),
label: CodeLabel::plain(word, None),
icon_path: None,