mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Remove UserStore from Worktree
This commit is contained in:
parent
6751bd9d78
commit
7de26302ec
2 changed files with 20 additions and 76 deletions
|
@ -230,17 +230,8 @@ impl Project {
|
||||||
|
|
||||||
let mut worktrees = Vec::new();
|
let mut worktrees = Vec::new();
|
||||||
for worktree in response.worktrees {
|
for worktree in response.worktrees {
|
||||||
worktrees.push(
|
worktrees
|
||||||
Worktree::remote(
|
.push(Worktree::remote(remote_id, replica_id, worktree, client.clone(), cx).await?);
|
||||||
remote_id,
|
|
||||||
replica_id,
|
|
||||||
worktree,
|
|
||||||
client.clone(),
|
|
||||||
user_store.clone(),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
.await?,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_ids = response
|
let user_ids = response
|
||||||
|
@ -891,11 +882,9 @@ impl Project {
|
||||||
) -> Task<Result<ModelHandle<Worktree>>> {
|
) -> Task<Result<ModelHandle<Worktree>>> {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
let user_store = self.user_store.clone();
|
|
||||||
let path = Arc::from(abs_path.as_ref());
|
let path = Arc::from(abs_path.as_ref());
|
||||||
cx.spawn(|project, mut cx| async move {
|
cx.spawn(|project, mut cx| async move {
|
||||||
let worktree =
|
let worktree = Worktree::open_local(client.clone(), path, weak, fs, &mut cx).await?;
|
||||||
Worktree::open_local(client.clone(), user_store, path, weak, fs, &mut cx).await?;
|
|
||||||
|
|
||||||
let (remote_project_id, is_shared) = project.update(&mut cx, |project, cx| {
|
let (remote_project_id, is_shared) = project.update(&mut cx, |project, cx| {
|
||||||
project.add_worktree(&worktree, cx);
|
project.add_worktree(&worktree, cx);
|
||||||
|
@ -1100,12 +1089,10 @@ impl Project {
|
||||||
.payload
|
.payload
|
||||||
.worktree
|
.worktree
|
||||||
.ok_or_else(|| anyhow!("invalid worktree"))?;
|
.ok_or_else(|| anyhow!("invalid worktree"))?;
|
||||||
let user_store = self.user_store.clone();
|
|
||||||
cx.spawn(|this, mut cx| {
|
cx.spawn(|this, mut cx| {
|
||||||
async move {
|
async move {
|
||||||
let worktree =
|
let worktree =
|
||||||
Worktree::remote(remote_id, replica_id, worktree, client, user_store, &mut cx)
|
Worktree::remote(remote_id, replica_id, worktree, client, &mut cx).await?;
|
||||||
.await?;
|
|
||||||
this.update(&mut cx, |this, cx| this.add_worktree(&worktree, cx));
|
this.update(&mut cx, |this, cx| this.add_worktree(&worktree, cx));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
|
use ::ignore::gitignore::{Gitignore, GitignoreBuilder};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use client::{proto, Client, PeerId, TypedEnvelope, UserStore};
|
use client::{proto, Client, PeerId, TypedEnvelope};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
use collections::{hash_map, HashMap, HashSet};
|
use collections::{hash_map, HashMap, HashSet};
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
|
@ -89,14 +89,12 @@ impl Entity for Worktree {
|
||||||
impl Worktree {
|
impl Worktree {
|
||||||
pub async fn open_local(
|
pub async fn open_local(
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
|
||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
weak: bool,
|
weak: bool,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> Result<ModelHandle<Self>> {
|
) -> Result<ModelHandle<Self>> {
|
||||||
let (tree, scan_states_tx) =
|
let (tree, scan_states_tx) = LocalWorktree::new(client, path, weak, fs.clone(), cx).await?;
|
||||||
LocalWorktree::new(client, user_store, path, weak, fs.clone(), cx).await?;
|
|
||||||
tree.update(cx, |tree, cx| {
|
tree.update(cx, |tree, cx| {
|
||||||
let tree = tree.as_local_mut().unwrap();
|
let tree = tree.as_local_mut().unwrap();
|
||||||
let abs_path = tree.snapshot.abs_path.clone();
|
let abs_path = tree.snapshot.abs_path.clone();
|
||||||
|
@ -117,7 +115,6 @@ impl Worktree {
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
worktree: proto::Worktree,
|
worktree: proto::Worktree,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
|
||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> Result<ModelHandle<Self>> {
|
) -> Result<ModelHandle<Self>> {
|
||||||
let remote_id = worktree.id;
|
let remote_id = worktree.id;
|
||||||
|
@ -225,7 +222,6 @@ impl Worktree {
|
||||||
loading_buffers: Default::default(),
|
loading_buffers: Default::default(),
|
||||||
open_buffers: Default::default(),
|
open_buffers: Default::default(),
|
||||||
queued_operations: Default::default(),
|
queued_operations: Default::default(),
|
||||||
user_store,
|
|
||||||
diagnostic_summaries,
|
diagnostic_summaries,
|
||||||
weak,
|
weak,
|
||||||
})
|
})
|
||||||
|
@ -304,13 +300,6 @@ impl Worktree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_store(&self) -> &ModelHandle<UserStore> {
|
|
||||||
match self {
|
|
||||||
Worktree::Local(worktree) => &worktree.user_store,
|
|
||||||
Worktree::Remote(worktree) => &worktree.user_store,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn diagnostic_summaries<'a>(
|
pub fn diagnostic_summaries<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
) -> impl Iterator<Item = (Arc<Path>, DiagnosticSummary)> + 'a {
|
) -> impl Iterator<Item = (Arc<Path>, DiagnosticSummary)> + 'a {
|
||||||
|
@ -390,7 +379,7 @@ impl Worktree {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "test-support")]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub(crate) fn has_open_buffer(&self, path: impl AsRef<Path>, cx: &AppContext) -> bool {
|
pub(crate) fn has_open_buffer(&self, path: impl AsRef<Path>, cx: &AppContext) -> bool {
|
||||||
let mut open_buffers: Box<dyn Iterator<Item = _>> = match self {
|
let mut open_buffers: Box<dyn Iterator<Item = _>> = match self {
|
||||||
Worktree::Local(worktree) => Box::new(worktree.open_buffers.values()),
|
Worktree::Local(worktree) => Box::new(worktree.open_buffers.values()),
|
||||||
|
@ -788,7 +777,6 @@ pub struct LocalWorktree {
|
||||||
diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>,
|
diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>,
|
||||||
queued_operations: Vec<(u64, Operation)>,
|
queued_operations: Vec<(u64, Operation)>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
weak: bool,
|
weak: bool,
|
||||||
}
|
}
|
||||||
|
@ -815,7 +803,6 @@ pub struct RemoteWorktree {
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
loading_buffers: LoadingBuffers,
|
loading_buffers: LoadingBuffers,
|
||||||
open_buffers: HashMap<usize, RemoteBuffer>,
|
open_buffers: HashMap<usize, RemoteBuffer>,
|
||||||
user_store: ModelHandle<UserStore>,
|
|
||||||
queued_operations: Vec<(u64, Operation)>,
|
queued_operations: Vec<(u64, Operation)>,
|
||||||
diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>,
|
diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>,
|
||||||
weak: bool,
|
weak: bool,
|
||||||
|
@ -836,7 +823,6 @@ struct WorktreeConfig {
|
||||||
impl LocalWorktree {
|
impl LocalWorktree {
|
||||||
async fn new(
|
async fn new(
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
|
||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
weak: bool,
|
weak: bool,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
@ -904,7 +890,6 @@ impl LocalWorktree {
|
||||||
diagnostic_summaries: Default::default(),
|
diagnostic_summaries: Default::default(),
|
||||||
queued_operations: Default::default(),
|
queued_operations: Default::default(),
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
fs,
|
fs,
|
||||||
weak,
|
weak,
|
||||||
};
|
};
|
||||||
|
@ -3075,7 +3060,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::fs::FakeFs;
|
use crate::fs::FakeFs;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use client::test::{FakeHttpClient, FakeServer};
|
use client::test::FakeHttpClient;
|
||||||
use fs::RealFs;
|
use fs::RealFs;
|
||||||
use language::{Diagnostic, DiagnosticEntry};
|
use language::{Diagnostic, DiagnosticEntry};
|
||||||
use lsp::Url;
|
use lsp::Url;
|
||||||
|
@ -3092,7 +3077,7 @@ mod tests {
|
||||||
use util::test::temp_tree;
|
use util::test::temp_tree;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_traversal(mut cx: gpui::TestAppContext) {
|
async fn test_traversal(cx: gpui::TestAppContext) {
|
||||||
let fs = FakeFs::new();
|
let fs = FakeFs::new();
|
||||||
fs.insert_tree(
|
fs.insert_tree(
|
||||||
"/root",
|
"/root",
|
||||||
|
@ -3107,12 +3092,10 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client);
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
Arc::from(Path::new("/root")),
|
Arc::from(Path::new("/root")),
|
||||||
false,
|
false,
|
||||||
Arc::new(fs),
|
Arc::new(fs),
|
||||||
|
@ -3145,12 +3128,10 @@ mod tests {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client);
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
dir.path(),
|
dir.path(),
|
||||||
false,
|
false,
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
|
@ -3180,12 +3161,10 @@ mod tests {
|
||||||
let file_path = dir.path().join("file1");
|
let file_path = dir.path().join("file1");
|
||||||
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client);
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
file_path.clone(),
|
file_path.clone(),
|
||||||
false,
|
false,
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
|
@ -3227,14 +3206,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let user_id = 5;
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let mut client = Client::new(http_client.clone());
|
let client = Client::new(http_client.clone());
|
||||||
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
|
|
||||||
let user_store = server.build_user_store(client.clone(), &mut cx).await;
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store.clone(),
|
|
||||||
dir.path(),
|
dir.path(),
|
||||||
false,
|
false,
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
|
@ -3275,7 +3250,6 @@ mod tests {
|
||||||
1,
|
1,
|
||||||
initial_snapshot.to_proto(&Default::default(), Default::default()),
|
initial_snapshot.to_proto(&Default::default(), Default::default()),
|
||||||
Client::new(http_client.clone()),
|
Client::new(http_client.clone()),
|
||||||
user_store,
|
|
||||||
&mut cx.to_async(),
|
&mut cx.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -3367,7 +3341,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_rescan_with_gitignore(mut cx: gpui::TestAppContext) {
|
async fn test_rescan_with_gitignore(cx: gpui::TestAppContext) {
|
||||||
let dir = temp_tree(json!({
|
let dir = temp_tree(json!({
|
||||||
".git": {},
|
".git": {},
|
||||||
".gitignore": "ignored-dir\n",
|
".gitignore": "ignored-dir\n",
|
||||||
|
@ -3381,11 +3355,9 @@ mod tests {
|
||||||
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client.clone());
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
dir.path(),
|
dir.path(),
|
||||||
false,
|
false,
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
|
@ -3420,11 +3392,8 @@ mod tests {
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_buffer_deduping(mut cx: gpui::TestAppContext) {
|
async fn test_buffer_deduping(mut cx: gpui::TestAppContext) {
|
||||||
let user_id = 100;
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let mut client = Client::new(http_client);
|
let client = Client::new(http_client);
|
||||||
let server = FakeServer::for_client(user_id, &mut client, &cx).await;
|
|
||||||
let user_store = server.build_user_store(client.clone(), &mut cx).await;
|
|
||||||
|
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
fs.insert_tree(
|
fs.insert_tree(
|
||||||
|
@ -3436,16 +3405,10 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let worktree = Worktree::open_local(
|
let worktree =
|
||||||
client.clone(),
|
Worktree::open_local(client, "/the-dir".as_ref(), false, fs, &mut cx.to_async())
|
||||||
user_store,
|
.await
|
||||||
"/the-dir".as_ref(),
|
.unwrap();
|
||||||
false,
|
|
||||||
fs,
|
|
||||||
&mut cx.to_async(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Spawn multiple tasks to open paths, repeating some paths.
|
// Spawn multiple tasks to open paths, repeating some paths.
|
||||||
let (buffer_a_1, buffer_b, buffer_a_2) = worktree.update(&mut cx, |worktree, cx| {
|
let (buffer_a_1, buffer_b, buffer_a_2) = worktree.update(&mut cx, |worktree, cx| {
|
||||||
|
@ -3489,11 +3452,9 @@ mod tests {
|
||||||
}));
|
}));
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client.clone());
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
dir.path(),
|
dir.path(),
|
||||||
false,
|
false,
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
|
@ -3625,12 +3586,10 @@ mod tests {
|
||||||
let initial_contents = "aaa\nbbbbb\nc\n";
|
let initial_contents = "aaa\nbbbbb\nc\n";
|
||||||
let dir = temp_tree(json!({ "the-file": initial_contents }));
|
let dir = temp_tree(json!({ "the-file": initial_contents }));
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client);
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
let tree = Worktree::open_local(
|
let tree = Worktree::open_local(
|
||||||
client,
|
client,
|
||||||
user_store,
|
|
||||||
dir.path(),
|
dir.path(),
|
||||||
false,
|
false,
|
||||||
Arc::new(RealFs),
|
Arc::new(RealFs),
|
||||||
|
@ -3726,7 +3685,6 @@ mod tests {
|
||||||
let fs = Arc::new(FakeFs::new());
|
let fs = Arc::new(FakeFs::new());
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client.clone());
|
let client = Client::new(http_client.clone());
|
||||||
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
|
|
||||||
|
|
||||||
fs.insert_tree(
|
fs.insert_tree(
|
||||||
"/the-dir",
|
"/the-dir",
|
||||||
|
@ -3745,7 +3703,6 @@ mod tests {
|
||||||
|
|
||||||
let worktree = Worktree::open_local(
|
let worktree = Worktree::open_local(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
user_store,
|
|
||||||
"/the-dir".as_ref(),
|
"/the-dir".as_ref(),
|
||||||
false,
|
false,
|
||||||
fs,
|
fs,
|
||||||
|
|
Loading…
Reference in a new issue