diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 30888d8a40..1ae9fdce27 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 33155b5d4f..df771a700a 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)) }) }) })