diff --git a/crates/editor/src/code_context_menus.rs b/crates/editor/src/code_context_menus.rs index 86af09309c049d4c2d97a24d29f93b2cf2849d03..753057c3da8d34404a1d6adb76f4c3c0e21e86e8 100644 --- a/crates/editor/src/code_context_menus.rs +++ b/crates/editor/src/code_context_menus.rs @@ -777,11 +777,34 @@ pub struct AvailableCodeAction { #[derive(Clone, Default)] pub struct CodeActionContents { - pub tasks: Option>, - pub actions: Option>, + tasks: Option>, + pub(crate) actions: Option>, } impl CodeActionContents { + pub fn new( + mut tasks: Option, + actions: Option>, + cx: &App, + ) -> Self { + if !cx.has_flag::() { + if let Some(tasks) = &mut tasks { + tasks + .templates + .retain(|(_, task)| !matches!(task.task_type(), task::TaskType::Debug(_))); + } + } + + Self { + tasks: tasks.map(Rc::new), + actions, + } + } + + pub fn tasks(&self) -> Option<&ResolvedTasks> { + self.tasks.as_deref() + } + fn len(&self) -> usize { match (&self.tasks, &self.actions) { (Some(tasks), Some(actions)) => actions.len() + tasks.templates.len(), @@ -989,17 +1012,6 @@ impl CodeActionsMenu { .iter() .skip(range.start) .take(range.end - range.start) - .filter(|action| { - if action - .as_task() - .map(|task| matches!(task.task_type(), task::TaskType::Debug(_))) - .unwrap_or(false) - { - cx.has_flag::() - } else { - true - } - }) .enumerate() .map(|(ix, action)| { let item_ix = range.start + ix; diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 6440dd860c7d5d644b7dd4dfdb277f3f79cff518..fd0b0c70a3ac5cbb3c33b497879afe3d99460322 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4914,26 +4914,24 @@ impl Editor { Self::build_tasks_context(&project, &buffer, buffer_row, tasks, cx) }); - cx.spawn_in(window, async move |_, _| { + cx.spawn_in(window, async move |_, cx| { let task_context = match task_context { Some(task_context) => task_context.await, None => None, }; - let resolved_tasks = tasks.zip(task_context).map(|(tasks, task_context)| { - Rc::new(ResolvedTasks { - templates: tasks.resolve(&task_context).collect(), - position: snapshot - .buffer_snapshot - .anchor_before(Point::new(multibuffer_point.row, tasks.column)), - }) - }); - Some(( - buffer, - CodeActionContents { - actions: code_actions, - tasks: resolved_tasks, - }, - )) + let resolved_tasks = + tasks + .zip(task_context) + .map(|(tasks, task_context)| ResolvedTasks { + templates: tasks.resolve(&task_context).collect(), + position: snapshot + .buffer_snapshot + .anchor_before(Point::new(multibuffer_point.row, tasks.column)), + }); + let code_action_contents = cx + .update(|_, cx| CodeActionContents::new(resolved_tasks, code_actions, cx)) + .ok()?; + Some((buffer, code_action_contents)) }) } @@ -4977,7 +4975,7 @@ impl Editor { Some(cx.spawn_in(window, async move |editor, cx| { if let Some((buffer, code_action_contents)) = code_actions_task.await { let spawn_straight_away = - code_action_contents.tasks.as_ref().map_or(false, |tasks| { + code_action_contents.tasks().map_or(false, |tasks| { tasks .templates .iter() diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 15e5b4d379439dc5a224716c2d5ddcbd1dffb8b0..c6a00fcdb8224b8d18aeb85181fc6c8e2006a5ea 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2093,8 +2093,7 @@ impl EditorElement { })) = editor.context_menu.borrow().as_ref() { actions - .tasks - .as_ref() + .tasks() .map(|tasks| tasks.position.to_display_point(snapshot).row()) .or(*deployed_from_indicator) } else {