Maintain on the background scanner a set of expanded directories

This commit is contained in:
Max Brunsfeld 2023-06-13 16:01:53 -07:00
parent a305d93567
commit 4c03231863
7 changed files with 250 additions and 48 deletions

View file

@ -51,6 +51,7 @@ 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;
@ -478,6 +479,8 @@ impl Project {
client.add_model_request_handler(Self::handle_rename_project_entry);
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);
@ -5403,6 +5406,56 @@ impl Project {
Some(ProjectPath { worktree_id, path })
}
pub fn mark_entry_expanded(
&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, true, 0, cx);
});
} else if let Some(project_id) = self.remote_id() {
cx.background()
.spawn(self.client.request(proto::ExpandProjectEntry {
project_id,
entry_id: entry_id.to_proto(),
}))
.log_err();
}
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)?
@ -5705,6 +5758,66 @@ impl Project {
})
}
async fn handle_expand_project_entry(
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))
})
.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,
)
});
Ok(proto::Ack {})
}
async fn handle_update_diagnostic_summary(
this: ModelHandle<Self>,
envelope: TypedEnvelope<proto::UpdateDiagnosticSummary>,