From 2b4738d82dc4c00827b7fffd3894aa25c592b6e6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 17 Mar 2022 17:34:35 +0100 Subject: [PATCH] Avoid passing a closure to `workspace::register_project_item` Co-Authored-By: Max Brunsfeld --- crates/editor/src/editor.rs | 4 +--- crates/workspace/src/workspace.rs | 11 +++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 30888d8a408ada78170e6dd6a39979392e085fe4..1ae9fdce27a9613c92ad6e2e1184e2de1304ef87 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -340,9 +340,7 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_async_action(Editor::confirm_rename); cx.add_async_action(Editor::find_all_references); - workspace::register_project_item(cx, |project, buffer, cx| { - Editor::for_buffer(buffer, Some(project), cx) - }); + workspace::register_project_item::(cx); } trait SelectionExt { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 33155b5d4f4710338d6c4d4570af129f21e92624..df771a700a84e0c63065a35032cf92d4634103c7 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -108,17 +108,16 @@ pub fn init(cx: &mut MutableAppContext) { ]); } -pub fn register_project_item(cx: &mut MutableAppContext, build_item: F) +pub fn register_project_item(cx: &mut MutableAppContext) where V: ProjectItem, - F: 'static + Fn(ModelHandle, ModelHandle, &mut ViewContext) -> V, { cx.update_default_global(|builders: &mut ItemBuilders, _| { builders.insert( TypeId::of::(), Arc::new(move |window_id, project, model, cx| { - let model = model.downcast::().unwrap(); - Box::new(cx.add_view(window_id, |cx| build_item(project, model, cx))) + let item = model.downcast::().unwrap(); + Box::new(cx.add_view(window_id, |cx| V::for_project_item(project, item, cx))) }), ); }); @@ -813,13 +812,13 @@ impl Workspace { let pane = self.active_pane().downgrade(); let task = self.load_path(path, cx); cx.spawn(|this, mut cx| async move { - let (project_entry_id, build_editor) = task.await?; + let (project_entry_id, build_item) = task.await?; let pane = pane .upgrade(&cx) .ok_or_else(|| anyhow!("pane was closed"))?; this.update(&mut cx, |_, cx| { pane.update(cx, |pane, cx| { - Ok(pane.open_item(project_entry_id, cx, build_editor)) + Ok(pane.open_item(project_entry_id, cx, build_item)) }) }) })