From bfa5dd52ddc1a57f79ea76d785abc106421fb1eb Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 29 Mar 2022 13:49:09 +0200 Subject: [PATCH] Don't underflow when calling `symbols_containing_offset(0)` --- crates/language/src/buffer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 36ef7d4a01..0c1ce7c228 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -1684,7 +1684,8 @@ impl BufferSnapshot { theme: Option<&SyntaxTheme>, ) -> Option>> { let position = position.to_offset(&self); - let mut items = self.outline_items_containing(position - 1..position + 1, theme)?; + let mut items = + self.outline_items_containing(position.saturating_sub(1)..position + 1, theme)?; let mut prev_depth = None; items.retain(|item| { let result = prev_depth.map_or(true, |prev_depth| item.depth > prev_depth);