From f0fe346e15180a3f959d8f51c2b8b788e68a3bc1 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 17 Dec 2021 16:37:12 +0100 Subject: [PATCH] Gracefully degrade `diagnostics_in_range`, `diagnostic_group` and `file` Co-Authored-By: Nathan Sobo --- crates/editor/src/multi_buffer.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index b94854d2f5c4347a4239280e87660aa961efe963..7f0b2ea736cf8bb70a3e693dccf566c479b628ad 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -685,7 +685,7 @@ impl MultiBuffer { } pub fn file<'a>(&self, cx: &'a AppContext) -> Option<&'a dyn File> { - self.as_singleton().unwrap().read(cx).file() + self.as_singleton()?.read(cx).file() } #[cfg(test)] @@ -1514,7 +1514,9 @@ impl MultiBufferSnapshot { where O: text::FromAnchor + 'a, { - self.as_singleton().unwrap().diagnostic_group(group_id) + self.as_singleton() + .into_iter() + .flat_map(move |buffer| buffer.diagnostic_group(group_id)) } pub fn diagnostics_in_range<'a, T, O>( @@ -1525,8 +1527,9 @@ impl MultiBufferSnapshot { T: 'a + ToOffset, O: 'a + text::FromAnchor, { - let range = range.start.to_offset(self)..range.end.to_offset(self); - self.as_singleton().unwrap().diagnostics_in_range(range) + self.as_singleton().into_iter().flat_map(move |buffer| { + buffer.diagnostics_in_range(range.start.to_offset(self)..range.end.to_offset(self)) + }) } pub fn range_for_syntax_ancestor(&self, range: Range) -> Option> {