Refactor opening workspace items

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-01-07 17:38:37 +01:00
parent 3cab32d201
commit 794d214eee
15 changed files with 281 additions and 257 deletions

View file

@ -51,11 +51,11 @@ fn main() {
let http = http::client();
let client = client::Client::new(http.clone());
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
let mut entry_openers = Vec::new();
let mut path_openers = Vec::new();
client::init(client.clone(), cx);
workspace::init(cx);
editor::init(cx, &mut entry_openers);
editor::init(cx, &mut path_openers);
go_to_line::init(cx);
file_finder::init(cx);
chat_panel::init(cx);
@ -72,7 +72,7 @@ fn main() {
client,
user_store,
fs: Arc::new(RealFs),
entry_openers: Arc::from(entry_openers),
path_openers: Arc::from(path_openers),
build_window_options: &build_window_options,
build_workspace: &build_workspace,
});

View file

@ -16,8 +16,8 @@ fn init_logger() {
}
pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
let mut entry_openers = Vec::new();
editor::init(cx, &mut entry_openers);
let mut path_openers = Vec::new();
editor::init(cx, &mut path_openers);
let (settings_tx, settings) = watch::channel_with(build_settings(cx));
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
let http = FakeHttpClient::with_404_response();
@ -41,7 +41,7 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
client,
user_store,
fs: Arc::new(FakeFs::new()),
entry_openers: Arc::from(entry_openers),
path_openers: Arc::from(path_openers),
build_window_options: &build_window_options,
build_workspace: &build_workspace,
})

View file

@ -62,7 +62,7 @@ pub fn build_workspace(
settings: app_state.settings.clone(),
user_store: app_state.user_store.clone(),
channel_list: app_state.channel_list.clone(),
entry_openers: app_state.entry_openers.clone(),
path_openers: app_state.path_openers.clone(),
};
let mut workspace = Workspace::new(&workspace_params, cx);
let project = workspace.project().clone();
@ -265,7 +265,6 @@ mod tests {
// Open the first entry
let entry_1 = workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx))
.unwrap()
.await
.unwrap();
cx.read(|cx| {
@ -274,13 +273,12 @@ mod tests {
pane.active_item().unwrap().project_path(cx),
Some(file1.clone())
);
assert_eq!(pane.items().len(), 1);
assert_eq!(pane.item_views().len(), 1);
});
// Open the second entry
workspace
.update(&mut cx, |w, cx| w.open_path(file2.clone(), cx))
.unwrap()
.await
.unwrap();
cx.read(|cx| {
@ -289,12 +287,12 @@ mod tests {
pane.active_item().unwrap().project_path(cx),
Some(file2.clone())
);
assert_eq!(pane.items().len(), 2);
assert_eq!(pane.item_views().len(), 2);
});
// Open the first entry again. The existing pane item is activated.
let entry_1b = workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx).unwrap())
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx))
.await
.unwrap();
assert_eq!(entry_1.id(), entry_1b.id());
@ -305,14 +303,14 @@ mod tests {
pane.active_item().unwrap().project_path(cx),
Some(file1.clone())
);
assert_eq!(pane.items().len(), 2);
assert_eq!(pane.item_views().len(), 2);
});
// Split the pane with the first entry, then open the second entry again.
workspace
.update(&mut cx, |w, cx| {
w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx);
w.open_path(file2.clone(), cx).unwrap()
w.open_path(file2.clone(), cx)
})
.await
.unwrap();
@ -331,8 +329,8 @@ mod tests {
// Open the third entry twice concurrently. Only one pane item is added.
let (t1, t2) = workspace.update(&mut cx, |w, cx| {
(
w.open_path(file3.clone(), cx).unwrap(),
w.open_path(file3.clone(), cx).unwrap(),
w.open_path(file3.clone(), cx),
w.open_path(file3.clone(), cx),
)
});
t1.await.unwrap();
@ -344,7 +342,7 @@ mod tests {
Some(file3.clone())
);
let pane_entries = pane
.items()
.item_views()
.iter()
.map(|i| i.project_path(cx).unwrap())
.collect::<Vec<_>>();
@ -561,15 +559,13 @@ mod tests {
workspace
.update(&mut cx, |workspace, cx| {
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
workspace
.open_path(
ProjectPath {
worktree_id: worktree.read(cx).id(),
path: Path::new("the-new-name.rs").into(),
},
cx,
)
.unwrap()
workspace.open_path(
ProjectPath {
worktree_id: worktree.read(cx).id(),
path: Path::new("the-new-name.rs").into(),
},
cx,
)
})
.await
.unwrap();
@ -667,7 +663,6 @@ mod tests {
workspace
.update(&mut cx, |w, cx| w.open_path(file1.clone(), cx))
.unwrap()
.await
.unwrap();
cx.read(|cx| {