debugger: Fix gutter tasks display for users without the debugger feature flag (#29056)

This commit is contained in:
Kirill Bulatov 2025-04-18 10:22:26 -06:00 committed by GitHub
parent 502a0f6535
commit 7badd6053d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 23 deletions

View file

@ -777,11 +777,34 @@ pub struct AvailableCodeAction {
#[derive(Clone)] #[derive(Clone)]
pub struct CodeActionContents { pub struct CodeActionContents {
pub tasks: Option<Rc<ResolvedTasks>>, tasks: Option<Rc<ResolvedTasks>>,
pub actions: Option<Rc<[AvailableCodeAction]>>, actions: Option<Rc<[AvailableCodeAction]>>,
} }
impl CodeActionContents { impl CodeActionContents {
pub fn new(
mut tasks: Option<ResolvedTasks>,
actions: Option<Rc<[AvailableCodeAction]>>,
cx: &App,
) -> Self {
if !cx.has_flag::<Debugger>() {
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 { fn len(&self) -> usize {
match (&self.tasks, &self.actions) { match (&self.tasks, &self.actions) {
(Some(tasks), Some(actions)) => actions.len() + tasks.templates.len(), (Some(tasks), Some(actions)) => actions.len() + tasks.templates.len(),
@ -989,17 +1012,6 @@ impl CodeActionsMenu {
.iter() .iter()
.skip(range.start) .skip(range.start)
.take(range.end - 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::<Debugger>()
} else {
true
}
})
.enumerate() .enumerate()
.map(|(ix, action)| { .map(|(ix, action)| {
let item_ix = range.start + ix; let item_ix = range.start + ix;

View file

@ -5013,15 +5013,15 @@ impl Editor {
None => None, None => None,
}; };
let resolved_tasks = let resolved_tasks =
tasks.zip(task_context).map(|(tasks, task_context)| { tasks
Rc::new(ResolvedTasks { .zip(task_context)
.map(|(tasks, task_context)| ResolvedTasks {
templates: tasks.resolve(&task_context).collect(), templates: tasks.resolve(&task_context).collect(),
position: snapshot.buffer_snapshot.anchor_before(Point::new( position: snapshot.buffer_snapshot.anchor_before(Point::new(
multibuffer_point.row, multibuffer_point.row,
tasks.column, tasks.column,
)), )),
}) });
});
let spawn_straight_away = resolved_tasks.as_ref().map_or(false, |tasks| { let spawn_straight_away = resolved_tasks.as_ref().map_or(false, |tasks| {
tasks tasks
.templates .templates
@ -5042,10 +5042,11 @@ impl Editor {
*editor.context_menu.borrow_mut() = *editor.context_menu.borrow_mut() =
Some(CodeContextMenu::CodeActions(CodeActionsMenu { Some(CodeContextMenu::CodeActions(CodeActionsMenu {
buffer, buffer,
actions: CodeActionContents { actions: CodeActionContents::new(
tasks: resolved_tasks, resolved_tasks,
actions: code_actions, code_actions,
}, cx,
),
selected_item: Default::default(), selected_item: Default::default(),
scroll_handle: UniformListScrollHandle::default(), scroll_handle: UniformListScrollHandle::default(),
deployed_from_indicator, deployed_from_indicator,

View file

@ -2092,8 +2092,7 @@ impl EditorElement {
})) = editor.context_menu.borrow().as_ref() })) = editor.context_menu.borrow().as_ref()
{ {
actions actions
.tasks .tasks()
.as_ref()
.map(|tasks| tasks.position.to_display_point(snapshot).row()) .map(|tasks| tasks.position.to_display_point(snapshot).row())
.or(*deployed_from_indicator) .or(*deployed_from_indicator)
} else { } else {