Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

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

Smit Barmase80727a03bf2b
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 7b987a6962a..296f6ca11de 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -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 {