Remove logic for marking worktree entries as collapsed

Max Brunsfeld created

Change summary

crates/collab/src/rpc.rs                  |  1 
crates/project/src/project.rs             | 84 ++----------------------
crates/project/src/worktree.rs            | 35 ++--------
crates/project_panel/src/project_panel.rs |  4 -
crates/rpc/proto/zed.proto                |  6 -
crates/rpc/src/proto.rs                   |  3 
6 files changed, 15 insertions(+), 118 deletions(-)

Detailed changes

crates/collab/src/rpc.rs 🔗

@@ -225,7 +225,6 @@ impl Server {
             .add_request_handler(forward_project_request::<proto::CopyProjectEntry>)
             .add_request_handler(forward_project_request::<proto::DeleteProjectEntry>)
             .add_request_handler(forward_project_request::<proto::ExpandProjectEntry>)
-            .add_request_handler(forward_project_request::<proto::CollapseProjectEntry>)
             .add_request_handler(forward_project_request::<proto::OnTypeFormatting>)
             .add_message_handler(create_buffer_for_peer)
             .add_request_handler(update_buffer)

crates/project/src/project.rs 🔗

@@ -51,7 +51,6 @@ use lsp_command::*;
 use postage::watch;
 use project_settings::ProjectSettings;
 use rand::prelude::*;
-use rpc::proto::PeerId;
 use search::SearchQuery;
 use serde::Serialize;
 use settings::SettingsStore;
@@ -480,7 +479,6 @@ impl Project {
         client.add_model_request_handler(Self::handle_copy_project_entry);
         client.add_model_request_handler(Self::handle_delete_project_entry);
         client.add_model_request_handler(Self::handle_expand_project_entry);
-        client.add_model_request_handler(Self::handle_collapse_project_entry);
         client.add_model_request_handler(Self::handle_apply_additional_edits_for_completion);
         client.add_model_request_handler(Self::handle_apply_code_action);
         client.add_model_request_handler(Self::handle_on_type_formatting);
@@ -5418,7 +5416,7 @@ impl Project {
                 worktree
                     .as_local_mut()
                     .unwrap()
-                    .mark_entry_expanded(entry_id, true, 0, cx);
+                    .mark_entry_expanded(entry_id, cx);
             });
         } else if let Some(project_id) = self.remote_id() {
             cx.background()
@@ -5431,31 +5429,6 @@ impl Project {
         Some(())
     }
 
-    pub fn mark_entry_collapsed(
-        &mut self,
-        worktree_id: WorktreeId,
-        entry_id: ProjectEntryId,
-        cx: &mut ModelContext<Self>,
-    ) -> Option<()> {
-        if self.is_local() {
-            let worktree = self.worktree_for_id(worktree_id, cx)?;
-            worktree.update(cx, |worktree, cx| {
-                worktree
-                    .as_local_mut()
-                    .unwrap()
-                    .mark_entry_expanded(entry_id, false, 0, cx);
-            });
-        } else if let Some(project_id) = self.remote_id() {
-            cx.background()
-                .spawn(self.client.request(proto::CollapseProjectEntry {
-                    project_id,
-                    entry_id: entry_id.to_proto(),
-                }))
-                .log_err();
-        }
-        Some(())
-    }
-
     pub fn absolute_path(&self, project_path: &ProjectPath, cx: &AppContext) -> Option<PathBuf> {
         let workspace_root = self
             .worktree_for_id(project_path.worktree_id, cx)?
@@ -5762,58 +5735,17 @@ impl Project {
         this: ModelHandle<Self>,
         envelope: TypedEnvelope<proto::ExpandProjectEntry>,
         _: Arc<Client>,
-        cx: AsyncAppContext,
-    ) -> Result<proto::Ack> {
-        Self::handle_expand_or_collapse_project_entry(
-            this,
-            envelope.payload.entry_id,
-            envelope.original_sender_id,
-            true,
-            cx,
-        )
-        .await
-    }
-
-    async fn handle_collapse_project_entry(
-        this: ModelHandle<Self>,
-        envelope: TypedEnvelope<proto::CollapseProjectEntry>,
-        _: Arc<Client>,
-        cx: AsyncAppContext,
-    ) -> Result<proto::Ack> {
-        Self::handle_expand_or_collapse_project_entry(
-            this,
-            envelope.payload.entry_id,
-            envelope.original_sender_id,
-            false,
-            cx,
-        )
-        .await
-    }
-
-    async fn handle_expand_or_collapse_project_entry(
-        this: ModelHandle<Self>,
-        entry_id: u64,
-        original_sender_id: Option<PeerId>,
-        is_expanded: bool,
         mut cx: AsyncAppContext,
     ) -> Result<proto::Ack> {
-        let entry_id = ProjectEntryId::from_proto(entry_id);
-        let (worktree, replica_id) = this
-            .read_with(&cx, |this, cx| {
-                let replica_id = original_sender_id
-                    .and_then(|peer_id| this.collaborators.get(&peer_id))?
-                    .replica_id;
-                let worktree = this.worktree_for_entry(entry_id, cx)?;
-                Some((worktree, replica_id))
-            })
+        let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id);
+        let worktree = this
+            .read_with(&cx, |this, cx| this.worktree_for_entry(entry_id, cx))
             .ok_or_else(|| anyhow!("invalid request"))?;
         worktree.update(&mut cx, |worktree, cx| {
-            worktree.as_local_mut().unwrap().mark_entry_expanded(
-                entry_id,
-                is_expanded,
-                replica_id,
-                cx,
-            )
+            worktree
+                .as_local_mut()
+                .unwrap()
+                .mark_entry_expanded(entry_id, cx)
         });
         Ok(proto::Ack {})
     }

crates/project/src/worktree.rs 🔗

@@ -5,7 +5,7 @@ use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
 use anyhow::{anyhow, Context, Result};
 use client::{proto, Client};
 use clock::ReplicaId;
-use collections::{BTreeSet, HashMap, VecDeque};
+use collections::{HashMap, HashSet, VecDeque};
 use fs::{
     repository::{GitFileStatus, GitRepository, RepoPath},
     Fs, LineEnding,
@@ -89,10 +89,8 @@ enum ScanRequest {
         paths: Vec<PathBuf>,
         done: barrier::Sender,
     },
-    SetDirExpanded {
+    ExpandDir {
         entry_id: ProjectEntryId,
-        replica_id: ReplicaId,
-        is_expanded: bool,
     },
 }
 
@@ -226,7 +224,7 @@ pub struct LocalSnapshot {
 
 struct BackgroundScannerState {
     snapshot: LocalSnapshot,
-    expanded_dirs: BTreeSet<(ProjectEntryId, ReplicaId)>,
+    expanded_dirs: HashSet<ProjectEntryId>,
     /// The ids of all of the entries that were removed from the snapshot
     /// as part of the current update. These entry ids may be re-used
     /// if the same inode is discovered at a new path, or if the given
@@ -1154,16 +1152,10 @@ impl LocalWorktree {
     pub fn mark_entry_expanded(
         &mut self,
         entry_id: ProjectEntryId,
-        is_expanded: bool,
-        replica_id: ReplicaId,
         _cx: &mut ModelContext<Worktree>,
     ) {
         self.scan_requests_tx
-            .try_send(ScanRequest::SetDirExpanded {
-                entry_id,
-                replica_id,
-                is_expanded,
-            })
+            .try_send(ScanRequest::ExpandDir { entry_id })
             .ok();
     }
 
@@ -2210,12 +2202,7 @@ impl LocalSnapshot {
 
 impl BackgroundScannerState {
     fn is_entry_expanded(&self, entry: &Entry) -> bool {
-        let expanded = self
-            .expanded_dirs
-            .range((entry.id, 0)..=(entry.id, ReplicaId::MAX))
-            .next()
-            .is_some();
-        expanded
+        self.expanded_dirs.contains(&entry.id)
     }
 
     fn reuse_entry_id(&mut self, entry: &mut Entry) {
@@ -2976,18 +2963,10 @@ impl BackgroundScanner {
                 self.reload_entries_for_paths(paths, None).await;
                 self.send_status_update(false, Some(done))
             }
-            ScanRequest::SetDirExpanded {
-                entry_id,
-                replica_id,
-                is_expanded,
-            } => {
+            ScanRequest::ExpandDir { entry_id } => {
                 let path = {
                     let mut state = self.state.lock();
-                    if is_expanded {
-                        state.expanded_dirs.insert((entry_id, replica_id));
-                    } else {
-                        state.expanded_dirs.remove(&(entry_id, replica_id));
-                    }
+                    state.expanded_dirs.insert(entry_id);
                     state
                         .snapshot
                         .entry_for_id(entry_id)

crates/project_panel/src/project_panel.rs 🔗

@@ -451,9 +451,6 @@ impl ProjectPanel {
                     Ok(ix) => {
                         expanded_dir_ids.remove(ix);
                         self.update_visible_entries(Some((worktree_id, entry_id)), cx);
-                        self.project.update(cx, |project, cx| {
-                            project.mark_entry_collapsed(worktree_id, entry_id, cx);
-                        });
                         cx.notify();
                         break;
                     }
@@ -477,7 +474,6 @@ impl ProjectPanel {
                 self.project.update(cx, |project, cx| {
                     match expanded_dir_ids.binary_search(&entry_id) {
                         Ok(ix) => {
-                            project.mark_entry_collapsed(worktree_id, entry_id, cx);
                             expanded_dir_ids.remove(ix);
                         }
                         Err(ix) => {

crates/rpc/proto/zed.proto 🔗

@@ -63,7 +63,6 @@ message Envelope {
         CopyProjectEntry copy_project_entry = 47;
         DeleteProjectEntry delete_project_entry = 48;
         ExpandProjectEntry expand_project_entry = 114;
-        CollapseProjectEntry collapse_project_entry = 115;
         ProjectEntryResponse project_entry_response = 49;
 
         UpdateDiagnosticSummary update_diagnostic_summary = 50;
@@ -379,11 +378,6 @@ message ExpandProjectEntry {
     uint64 entry_id = 2;
 }
 
-message CollapseProjectEntry {
-    uint64 project_id = 1;
-    uint64 entry_id = 2;
-}
-
 message ProjectEntryResponse {
     Entry entry = 1;
     uint64 worktree_scan_id = 2;

crates/rpc/src/proto.rs 🔗

@@ -151,7 +151,6 @@ messages!(
     (DeleteProjectEntry, Foreground),
     (Error, Foreground),
     (ExpandProjectEntry, Foreground),
-    (CollapseProjectEntry, Foreground),
     (Follow, Foreground),
     (FollowResponse, Foreground),
     (FormatBuffers, Foreground),
@@ -258,7 +257,6 @@ request_messages!(
     (DeclineCall, Ack),
     (DeleteProjectEntry, ProjectEntryResponse),
     (ExpandProjectEntry, Ack),
-    (CollapseProjectEntry, Ack),
     (Follow, FollowResponse),
     (FormatBuffers, FormatBuffersResponse),
     (GetChannelMessages, GetChannelMessagesResponse),
@@ -316,7 +314,6 @@ entity_messages!(
     CreateProjectEntry,
     DeleteProjectEntry,
     ExpandProjectEntry,
-    CollapseProjectEntry,
     Follow,
     FormatBuffers,
     GetCodeActions,