Rename weak
to visible
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
a3c8892252
commit
68cfce1fb8
12 changed files with 95 additions and 96 deletions
|
@ -485,10 +485,10 @@ impl Project {
|
|||
) -> impl 'a + Iterator<Item = ModelHandle<Worktree>> {
|
||||
self.worktrees.iter().filter_map(|worktree| {
|
||||
worktree.upgrade(cx).and_then(|worktree| {
|
||||
if worktree.read(cx).is_weak() {
|
||||
None
|
||||
} else {
|
||||
if worktree.read(cx).is_visible() {
|
||||
Some(worktree)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -589,7 +589,7 @@ impl Project {
|
|||
for worktree_handle in this.worktrees.iter_mut() {
|
||||
match worktree_handle {
|
||||
WorktreeHandle::Strong(worktree) => {
|
||||
if worktree.read(cx).is_weak() {
|
||||
if !worktree.read(cx).is_visible() {
|
||||
*worktree_handle = WorktreeHandle::Weak(worktree.downgrade());
|
||||
}
|
||||
}
|
||||
|
@ -768,7 +768,7 @@ impl Project {
|
|||
} else {
|
||||
let worktree = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.create_local_worktree(&abs_path, true, cx)
|
||||
this.create_local_worktree(&abs_path, false, cx)
|
||||
})
|
||||
.await?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
|
@ -793,7 +793,7 @@ impl Project {
|
|||
abs_path: PathBuf,
|
||||
cx: &mut ModelContext<Project>,
|
||||
) -> Task<Result<()>> {
|
||||
let worktree_task = self.find_or_create_local_worktree(&abs_path, false, cx);
|
||||
let worktree_task = self.find_or_create_local_worktree(&abs_path, true, cx);
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let (worktree, path) = worktree_task.await?;
|
||||
worktree
|
||||
|
@ -2301,14 +2301,14 @@ impl Project {
|
|||
pub fn find_or_create_local_worktree(
|
||||
&self,
|
||||
abs_path: impl AsRef<Path>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<(ModelHandle<Worktree>, PathBuf)>> {
|
||||
let abs_path = abs_path.as_ref();
|
||||
if let Some((tree, relative_path)) = self.find_local_worktree(abs_path, cx) {
|
||||
Task::ready(Ok((tree.clone(), relative_path.into())))
|
||||
} else {
|
||||
let worktree = self.create_local_worktree(abs_path, weak, cx);
|
||||
let worktree = self.create_local_worktree(abs_path, visible, cx);
|
||||
cx.foreground()
|
||||
.spawn(async move { Ok((worktree.await?, PathBuf::new())) })
|
||||
}
|
||||
|
@ -2341,14 +2341,14 @@ impl Project {
|
|||
fn create_local_worktree(
|
||||
&self,
|
||||
abs_path: impl AsRef<Path>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<ModelHandle<Worktree>>> {
|
||||
let fs = self.fs.clone();
|
||||
let client = self.client.clone();
|
||||
let path = Arc::from(abs_path.as_ref());
|
||||
cx.spawn(|project, mut cx| async move {
|
||||
let worktree = Worktree::local(client.clone(), path, weak, fs, &mut cx).await?;
|
||||
let worktree = Worktree::local(client.clone(), path, visible, fs, &mut cx).await?;
|
||||
|
||||
let (remote_project_id, is_shared) = project.update(&mut cx, |project, cx| {
|
||||
project.add_worktree(&worktree, cx);
|
||||
|
@ -2394,7 +2394,7 @@ impl Project {
|
|||
|
||||
let push_strong_handle = {
|
||||
let worktree = worktree.read(cx);
|
||||
self.is_shared() || worktree.is_remote()
|
||||
self.is_shared() || worktree.is_visible() || worktree.is_remote()
|
||||
};
|
||||
if push_strong_handle {
|
||||
self.worktrees
|
||||
|
@ -2627,7 +2627,7 @@ impl Project {
|
|||
root_name: envelope.payload.root_name,
|
||||
entries: Default::default(),
|
||||
diagnostic_summaries: Default::default(),
|
||||
weak: envelope.payload.weak,
|
||||
visible: envelope.payload.visible,
|
||||
};
|
||||
let (worktree, load_task) =
|
||||
Worktree::remote(remote_id, replica_id, worktree, client, cx);
|
||||
|
@ -3361,7 +3361,7 @@ impl Project {
|
|||
) -> impl 'a + Future<Output = Vec<PathMatch>> {
|
||||
let worktrees = self
|
||||
.worktrees(cx)
|
||||
.filter(|worktree| !worktree.read(cx).is_weak())
|
||||
.filter(|worktree| worktree.read(cx).is_visible())
|
||||
.collect::<Vec<_>>();
|
||||
let include_root_name = worktrees.len() > 1;
|
||||
let candidate_sets = worktrees
|
||||
|
@ -3656,7 +3656,7 @@ mod tests {
|
|||
|
||||
let (tree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree(&root_link_path, false, cx)
|
||||
project.find_or_create_local_worktree(&root_link_path, true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -3725,7 +3725,7 @@ mod tests {
|
|||
|
||||
let (tree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/dir", false, cx)
|
||||
project.find_or_create_local_worktree("/dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -3823,7 +3823,7 @@ mod tests {
|
|||
let project = Project::test(Arc::new(RealFs), cx);
|
||||
let (tree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree(&dir.path(), false, cx)
|
||||
project.find_or_create_local_worktree(&dir.path(), true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -3871,7 +3871,7 @@ mod tests {
|
|||
|
||||
let (tree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/dir/b.rs", false, cx)
|
||||
project.find_or_create_local_worktree("/dir/b.rs", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -3928,16 +3928,13 @@ mod tests {
|
|||
assert_eq!(definition.range.to_offset(target_buffer), 9..10);
|
||||
assert_eq!(
|
||||
list_worktrees(&project, cx),
|
||||
[("/dir/b.rs".as_ref(), false), ("/dir/a.rs".as_ref(), true)]
|
||||
[("/dir/b.rs".as_ref(), true), ("/dir/a.rs".as_ref(), false)]
|
||||
);
|
||||
|
||||
drop(definition);
|
||||
});
|
||||
cx.read(|cx| {
|
||||
assert_eq!(
|
||||
list_worktrees(&project, cx),
|
||||
[("/dir/b.rs".as_ref(), false)]
|
||||
);
|
||||
assert_eq!(list_worktrees(&project, cx), [("/dir/b.rs".as_ref(), true)]);
|
||||
});
|
||||
|
||||
fn list_worktrees<'a>(
|
||||
|
@ -3951,7 +3948,7 @@ mod tests {
|
|||
let worktree = worktree.read(cx);
|
||||
(
|
||||
worktree.as_local().unwrap().abs_path().as_ref(),
|
||||
worktree.is_weak(),
|
||||
worktree.is_visible(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
|
@ -3972,7 +3969,7 @@ mod tests {
|
|||
let project = Project::test(fs.clone(), cx);
|
||||
let worktree_id = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree("/dir", false, cx)
|
||||
p.find_or_create_local_worktree("/dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
|
@ -4010,7 +4007,7 @@ mod tests {
|
|||
let project = Project::test(fs.clone(), cx);
|
||||
let worktree_id = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree("/dir/file1", false, cx)
|
||||
p.find_or_create_local_worktree("/dir/file1", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
|
@ -4054,7 +4051,7 @@ mod tests {
|
|||
|
||||
let (tree, _) = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree(dir.path(), false, cx)
|
||||
p.find_or_create_local_worktree(dir.path(), true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -4091,7 +4088,7 @@ mod tests {
|
|||
Worktree::remote(
|
||||
1,
|
||||
1,
|
||||
initial_snapshot.to_proto(&Default::default(), Default::default()),
|
||||
initial_snapshot.to_proto(&Default::default(), true),
|
||||
rpc.clone(),
|
||||
cx,
|
||||
)
|
||||
|
@ -4200,7 +4197,7 @@ mod tests {
|
|||
let project = Project::test(fs.clone(), cx);
|
||||
let worktree_id = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree("/the-dir", false, cx)
|
||||
p.find_or_create_local_worktree("/the-dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
|
@ -4250,7 +4247,7 @@ mod tests {
|
|||
let project = Project::test(Arc::new(RealFs), cx);
|
||||
let (worktree, _) = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree(dir.path(), false, cx)
|
||||
p.find_or_create_local_worktree(dir.path(), true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -4384,7 +4381,7 @@ mod tests {
|
|||
let project = Project::test(Arc::new(RealFs), cx);
|
||||
let (worktree, _) = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree(dir.path(), false, cx)
|
||||
p.find_or_create_local_worktree(dir.path(), true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -4493,7 +4490,7 @@ mod tests {
|
|||
let project = Project::test(fs.clone(), cx);
|
||||
let (worktree, _) = project
|
||||
.update(cx, |p, cx| {
|
||||
p.find_or_create_local_worktree("/the-dir", false, cx)
|
||||
p.find_or_create_local_worktree("/the-dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -4761,7 +4758,7 @@ mod tests {
|
|||
|
||||
let (tree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/dir", false, cx)
|
||||
project.find_or_create_local_worktree("/dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -4889,7 +4886,7 @@ mod tests {
|
|||
let project = Project::test(fs.clone(), cx);
|
||||
let (tree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/dir", false, cx)
|
||||
project.find_or_create_local_worktree("/dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
|
@ -71,7 +71,7 @@ pub struct LocalWorktree {
|
|||
queued_operations: Vec<(u64, Operation)>,
|
||||
client: Arc<Client>,
|
||||
fs: Arc<dyn Fs>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
}
|
||||
|
||||
pub struct RemoteWorktree {
|
||||
|
@ -83,7 +83,7 @@ pub struct RemoteWorktree {
|
|||
replica_id: ReplicaId,
|
||||
queued_operations: Vec<(u64, Operation)>,
|
||||
diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -169,11 +169,12 @@ impl Worktree {
|
|||
pub async fn local(
|
||||
client: Arc<Client>,
|
||||
path: impl Into<Arc<Path>>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<ModelHandle<Self>> {
|
||||
let (tree, scan_states_tx) = LocalWorktree::new(client, path, weak, fs.clone(), cx).await?;
|
||||
let (tree, scan_states_tx) =
|
||||
LocalWorktree::new(client, path, visible, fs.clone(), cx).await?;
|
||||
tree.update(cx, |tree, cx| {
|
||||
let tree = tree.as_local_mut().unwrap();
|
||||
let abs_path = tree.abs_path().clone();
|
||||
|
@ -203,7 +204,7 @@ impl Worktree {
|
|||
.map(|c| c.to_ascii_lowercase())
|
||||
.collect();
|
||||
let root_name = worktree.root_name.clone();
|
||||
let weak = worktree.weak;
|
||||
let visible = worktree.visible;
|
||||
let snapshot = Snapshot {
|
||||
id: WorktreeId(remote_id as usize),
|
||||
root_name,
|
||||
|
@ -236,7 +237,7 @@ impl Worktree {
|
|||
)
|
||||
}),
|
||||
),
|
||||
weak,
|
||||
visible,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -356,10 +357,10 @@ impl Worktree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_weak(&self) -> bool {
|
||||
pub fn is_visible(&self) -> bool {
|
||||
match self {
|
||||
Worktree::Local(worktree) => worktree.weak,
|
||||
Worktree::Remote(worktree) => worktree.weak,
|
||||
Worktree::Local(worktree) => worktree.visible,
|
||||
Worktree::Remote(worktree) => worktree.visible,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,7 +459,7 @@ impl LocalWorktree {
|
|||
async fn new(
|
||||
client: Arc<Client>,
|
||||
path: impl Into<Arc<Path>>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<(ModelHandle<Worktree>, UnboundedSender<ScanState>)> {
|
||||
|
@ -525,7 +526,7 @@ impl LocalWorktree {
|
|||
queued_operations: Default::default(),
|
||||
client,
|
||||
fs,
|
||||
weak,
|
||||
visible,
|
||||
};
|
||||
|
||||
cx.spawn_weak(|this, mut cx| async move {
|
||||
|
@ -738,7 +739,7 @@ impl LocalWorktree {
|
|||
worktree_id: self.id().to_proto(),
|
||||
root_name: self.root_name().to_string(),
|
||||
authorized_logins: self.authorized_logins(),
|
||||
weak: self.weak,
|
||||
visible: self.visible,
|
||||
};
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let response = client.request(register_message).await;
|
||||
|
@ -1028,7 +1029,7 @@ impl LocalSnapshot {
|
|||
pub(crate) fn to_proto(
|
||||
&self,
|
||||
diagnostic_summaries: &TreeMap<PathKey, DiagnosticSummary>,
|
||||
weak: bool,
|
||||
visible: bool,
|
||||
) -> proto::Worktree {
|
||||
let root_name = self.root_name.clone();
|
||||
proto::Worktree {
|
||||
|
@ -1044,7 +1045,7 @@ impl LocalSnapshot {
|
|||
.iter()
|
||||
.map(|(path, summary)| summary.to_proto(&path.0))
|
||||
.collect(),
|
||||
weak,
|
||||
visible,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2468,7 +2469,7 @@ mod tests {
|
|||
let tree = Worktree::local(
|
||||
client,
|
||||
Arc::from(Path::new("/root")),
|
||||
false,
|
||||
true,
|
||||
fs,
|
||||
&mut cx.to_async(),
|
||||
)
|
||||
|
@ -2511,7 +2512,7 @@ mod tests {
|
|||
let tree = Worktree::local(
|
||||
client,
|
||||
dir.path(),
|
||||
false,
|
||||
true,
|
||||
Arc::new(RealFs),
|
||||
&mut cx.to_async(),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue