From 3245e4f8d70b88edb37d9758539990207be4bc06 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 24 Aug 2022 15:10:53 -0700 Subject: [PATCH] Fix out-of-range panic when requesting outline items at EOF --- crates/language/src/buffer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 7b298b7420..80b9cdbaa3 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -1953,8 +1953,10 @@ impl BufferSnapshot { theme: Option<&SyntaxTheme>, ) -> Option>> { let position = position.to_offset(self); - let mut items = - self.outline_items_containing(position.saturating_sub(1)..position + 1, theme)?; + let mut items = self.outline_items_containing( + position.saturating_sub(1)..self.len().min(position + 1), + theme, + )?; let mut prev_depth = None; items.retain(|item| { let result = prev_depth.map_or(true, |prev_depth| item.depth > prev_depth);