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 \<conrad@zed.dev\>
Co-authored-by: Ben Kunkle \<ben@zed.dev\>
Co-authored-by: Cole Miller \<cole@zed.dev\>

Release Notes:

- N/A
This commit is contained in:
Anthony Eid 2025-06-04 00:08:59 +03:00 committed by GitHub
parent b9256dd469
commit 81f8e2ed4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3283,8 +3283,8 @@ impl BufferSnapshot {
pub fn surrounding_word<T: ToOffset>(&self, start: T) -> (Range<usize>, Option<CharKind>) {
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(