From 6e7101ca6bc4eb270c2ef80d54ca897402d8ce11 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Wed, 25 Jan 2023 17:47:15 -0500 Subject: [PATCH] Fix crash when opening feedback while in call --- crates/feedback/src/feedback.rs | 6 ++-- crates/feedback/src/feedback_editor.rs | 46 +++++++++++++++++--------- crates/zed/src/main.rs | 2 +- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/crates/feedback/src/feedback.rs b/crates/feedback/src/feedback.rs index 4b0dfc4df9..f47f95d4f3 100644 --- a/crates/feedback/src/feedback.rs +++ b/crates/feedback/src/feedback.rs @@ -5,7 +5,7 @@ mod system_specs; use gpui::{actions, impl_actions, ClipboardItem, ViewContext}; use serde::Deserialize; use system_specs::SystemSpecs; -use workspace::Workspace; +use workspace::{AppState, Workspace}; #[derive(Deserialize, Clone, PartialEq)] pub struct OpenBrowser { @@ -19,8 +19,8 @@ actions!( [CopySystemSpecsIntoClipboard, FileBugReport, RequestFeature,] ); -pub fn init(cx: &mut gpui::MutableAppContext) { - feedback_editor::init(cx); +pub fn init(app_state: Arc, cx: &mut gpui::MutableAppContext) { + feedback_editor::init(app_state, cx); cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url)); diff --git a/crates/feedback/src/feedback_editor.rs b/crates/feedback/src/feedback_editor.rs index e034da7db2..e57b81a15c 100644 --- a/crates/feedback/src/feedback_editor.rs +++ b/crates/feedback/src/feedback_editor.rs @@ -26,7 +26,7 @@ use settings::Settings; use workspace::{ item::{Item, ItemHandle}, searchable::{SearchableItem, SearchableItemHandle}, - StatusItemView, Workspace, + AppState, StatusItemView, Workspace, }; use crate::system_specs::SystemSpecs; @@ -43,8 +43,12 @@ const FEEDBACK_SUBMISSION_ERROR_TEXT: &str = actions!(feedback, [SubmitFeedback, GiveFeedback, DeployFeedback]); -pub fn init(cx: &mut MutableAppContext) { - cx.add_action(FeedbackEditor::deploy); +pub fn init(app_state: Arc, cx: &mut MutableAppContext) { + cx.add_action({ + move |workspace: &mut Workspace, _: &GiveFeedback, cx: &mut ViewContext| { + FeedbackEditor::deploy(workspace, app_state.clone(), cx); + } + }); } pub struct FeedbackButton; @@ -116,15 +120,11 @@ impl FeedbackEditor { Self { editor, project } } - fn new(project: ModelHandle, cx: &mut ViewContext) -> Self { - let markdown_language = project.read(cx).languages().language_for_name("Markdown"); - - let buffer = project - .update(cx, |project, cx| { - project.create_buffer("", markdown_language, cx) - }) - .expect("creating buffers on a local workspace always succeeds"); - + fn new( + project: ModelHandle, + buffer: ModelHandle, + cx: &mut ViewContext, + ) -> Self { Self::new_with_buffer(project, buffer, cx) } @@ -236,10 +236,24 @@ impl FeedbackEditor { } impl FeedbackEditor { - pub fn deploy(workspace: &mut Workspace, _: &GiveFeedback, cx: &mut ViewContext) { - let feedback_editor = - cx.add_view(|cx| FeedbackEditor::new(workspace.project().clone(), cx)); - workspace.add_item(Box::new(feedback_editor), cx); + pub fn deploy( + workspace: &mut Workspace, + app_state: Arc, + cx: &mut ViewContext, + ) { + workspace + .with_local_workspace(&app_state, cx, |workspace, cx| { + let project = workspace.project().clone(); + let markdown_language = project.read(cx).languages().language_for_name("Markdown"); + let buffer = project + .update(cx, |project, cx| { + project.create_buffer("", markdown_language, cx) + }) + .expect("creating buffers on a local workspace always succeeds"); + let feedback_editor = cx.add_view(|cx| FeedbackEditor::new(project, buffer, cx)); + workspace.add_item(Box::new(feedback_editor), cx); + }) + .detach(); } } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 79183f3128..3cd01a18a1 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -136,7 +136,6 @@ fn main() { client::init(client.clone(), cx); command_palette::init(cx); editor::init(cx); - feedback::init(cx); go_to_line::init(cx); file_finder::init(cx); outline::init(cx); @@ -191,6 +190,7 @@ fn main() { theme_selector::init(app_state.clone(), cx); zed::init(&app_state, cx); collab_ui::init(app_state.clone(), cx); + feedback::init(app_state.clone(), cx); cx.set_menus(menus::menus());