editor: Limit snippet query range instead of collecting from buffer start (#39617)

Fixes hang when computing query for snippet completions when working
with really large buffers.

Release Notes:

- N/A
This commit is contained in:
Smit Barmase
2025-10-06 20:54:42 +05:30
committed by GitHub
parent e7339fbd42
commit 80727a03bf
+9 -7
View File
@@ -22794,9 +22794,6 @@ fn snippet_completions(
}
let snapshot = buffer.read(cx).text_snapshot();
let chars: String = snapshot
.reversed_chars_for_range(text::Anchor::MIN..buffer_position)
.collect();
let executor = cx.background_executor().clone();
cx.background_spawn(async move {
@@ -22805,11 +22802,16 @@ fn snippet_completions(
for (scope, snippets) in scopes.into_iter() {
let classifier =
CharClassifier::new(Some(scope)).scope_context(Some(CharScopeContext::Completion));
let mut last_word = chars
.chars()
const MAX_WORD_PREFIX_LEN: usize = 128;
let last_word: String = snapshot
.reversed_chars_for_range(text::Anchor::MIN..buffer_position)
.take(MAX_WORD_PREFIX_LEN)
.take_while(|c| classifier.is_word(*c))
.collect::<String>();
last_word = last_word.chars().rev().collect();
.collect::<String>()
.chars()
.rev()
.collect();
if last_word.is_empty() {
return Ok(CompletionResponse {