From 81f8e2ed4aeaefe9d7b9ad8cce9df1c335046bfd Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Wed, 4 Jun 2025 00:08:59 +0300 Subject: [PATCH] Limit BufferSnapshot::surrounding_word search to 256 characters (#32016) This is the first step to closing #16120. Part of the problem was that `surrounding_word` would search the whole line for matches with no limit. Co-authored-by: Conrad Irwin \ Co-authored-by: Ben Kunkle \ Co-authored-by: Cole Miller \ Release Notes: - N/A --- crates/language/src/buffer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 2d298ff24b..ef7a22d7e7 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -3283,8 +3283,8 @@ impl BufferSnapshot { pub fn surrounding_word(&self, start: T) -> (Range, Option) { let mut start = start.to_offset(self); let mut end = start; - let mut next_chars = self.chars_at(start).peekable(); - let mut prev_chars = self.reversed_chars_at(start).peekable(); + let mut next_chars = self.chars_at(start).take(128).peekable(); + let mut prev_chars = self.reversed_chars_at(start).take(128).peekable(); let classifier = self.char_classifier_at(start); let word_kind = cmp::max(