Reduce accessibility of multibuffer read to reduce risk of borrowing snapshot and buffer refcells twice

This commit is contained in:
Keith Simmons 2022-05-13 16:58:30 -07:00
parent 2f7eb6dbc5
commit a2fd41174f
9 changed files with 36 additions and 17 deletions

View file

@ -226,7 +226,7 @@ impl MultiBuffer {
self.snapshot.borrow().clone()
}
pub fn read(&self, cx: &AppContext) -> Ref<MultiBufferSnapshot> {
pub(crate) fn read(&self, cx: &AppContext) -> Ref<MultiBufferSnapshot> {
self.sync(cx);
self.snapshot.borrow()
}
@ -255,6 +255,27 @@ impl MultiBuffer {
self.subscriptions.subscribe()
}
pub fn is_dirty(&self, cx: &AppContext) -> bool {
self.read(cx).is_dirty()
}
pub fn has_conflict(&self, cx: &AppContext) -> bool {
self.read(cx).has_conflict()
}
pub fn len(&self, cx: &AppContext) -> usize {
self.read(cx).len()
}
pub fn symbols_containing<T: ToOffset>(
&self,
offset: T,
theme: Option<&SyntaxTheme>,
cx: &AppContext,
) -> Option<(usize, Vec<OutlineItem<Anchor>>)> {
self.read(cx).symbols_containing(offset, theme)
}
pub fn edit<I, S, T>(&mut self, edits: I, cx: &mut ModelContext<Self>)
where
I: IntoIterator<Item = (Range<S>, T)>,