From 77cdbdb12ae3edbdbc9fd711ff08f7aa8adff2fe Mon Sep 17 00:00:00 2001 From: Mikayla Date: Sat, 9 Sep 2023 12:10:18 -0700 Subject: [PATCH] remove extraneous depth field --- crates/channel/src/channel_store.rs | 5 ++--- .../src/channel_store/channel_index.rs | 22 +++++++++++-------- crates/collab_ui/src/collab_panel.rs | 3 ++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/channel/src/channel_store.rs b/crates/channel/src/channel_store.rs index 2aeff3afef..b7681c6ec7 100644 --- a/crates/channel/src/channel_store.rs +++ b/crates/channel/src/channel_store.rs @@ -146,13 +146,12 @@ impl ChannelStore { }) } - pub fn channel_at_index(&self, ix: usize) -> Option<(usize, &Arc, &Arc<[ChannelId]>)> { + pub fn channel_at_index(&self, ix: usize) -> Option<(&Arc, &Arc<[ChannelId]>)> { let path = self.channel_index.get(ix)?; let id = path.last().unwrap(); let channel = self.channel_for_id(*id).unwrap(); - - Some((path.len() - 1, channel, path)) + Some((channel, path)) } pub fn channel_invitations(&self) -> &[Arc] { diff --git a/crates/channel/src/channel_store/channel_index.rs b/crates/channel/src/channel_store/channel_index.rs index b52d7ba334..e64c5cff5c 100644 --- a/crates/channel/src/channel_store/channel_index.rs +++ b/crates/channel/src/channel_store/channel_index.rs @@ -1,4 +1,4 @@ -use std::{ops::Deref, sync::Arc}; +use std::sync::Arc; use collections::HashMap; use rpc::proto; @@ -25,6 +25,18 @@ impl ChannelIndex { self.channels_by_id.clear(); } + pub fn len(&self) -> usize { + self.paths.len() + } + + pub fn get(&self, idx: usize) -> Option<&ChannelPath> { + self.paths.get(idx) + } + + pub fn iter(&self) -> impl Iterator { + self.paths.iter() + } + /// Remove the given edge from this index. This will not remove the channel /// and may result in dangling channels. pub fn delete_edge(&mut self, parent_id: ChannelId, channel_id: ChannelId) { @@ -50,14 +62,6 @@ impl ChannelIndex { } } -impl Deref for ChannelIndex { - type Target = Vec; - - fn deref(&self) -> &Self::Target { - &self.paths - } -} - /// A guard for ensuring that the paths index maintains its sort and uniqueness /// invariants after a series of insertions pub struct ChannelPathsUpsertGuard<'a> { diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index c9d5d97305..9c21633c86 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -785,8 +785,9 @@ impl CollabPanel { } let mut collapse_depth = None; for mat in matches { - let (depth, channel, path) = + let (channel, path) = channel_store.channel_at_index(mat.candidate_id).unwrap(); + let depth = path.len() - 1; let location: ChannelLocation<'_> = (channel.id, path).into();