Change summary
crates/editor/src/editor.rs | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
Detailed changes
@@ -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 {