Debugger implementation (#13433)

###  DISCLAIMER

> As of 6th March 2025, debugger is still in development. We plan to
merge it behind a staff-only feature flag for staff use only, followed
by non-public release and then finally a public one (akin to how Git
panel release was handled). This is done to ensure the best experience
when it gets released.

### END OF DISCLAIMER 

**The current state of the debugger implementation:**


https://github.com/user-attachments/assets/c4deff07-80dd-4dc6-ad2e-0c252a478fe9


https://github.com/user-attachments/assets/e1ed2345-b750-4bb6-9c97-50961b76904f

----

All the todo's are in the following channel, so it's easier to work on
this together:
https://zed.dev/channel/zed-debugger-11370

If you are on Linux, you can use the following command to join the
channel:
```cli
zed https://zed.dev/channel/zed-debugger-11370 
```

## Current Features

- Collab
  - Breakpoints
    - Sync when you (re)join a project
    - Sync when you add/remove a breakpoint
  - Sync active debug line
  - Stack frames
    - Click on stack frame
      - View variables that belong to the stack frame
      - Visit the source file
    - Restart stack frame (if adapter supports this)
  - Variables
  - Loaded sources
  - Modules
  - Controls
    - Continue
    - Step back
      - Stepping granularity (configurable)
    - Step into
      - Stepping granularity (configurable)
    - Step over
      - Stepping granularity (configurable)
    - Step out
      - Stepping granularity (configurable)
  - Debug console
- Breakpoints
  - Log breakpoints
  - line breakpoints
  - Persistent between zed sessions (configurable)
  - Multi buffer support
  - Toggle disable/enable all breakpoints
- Stack frames
  - Click on stack frame
    - View variables that belong to the stack frame
    - Visit the source file
    - Show collapsed stack frames
  - Restart stack frame (if adapter supports this)
- Loaded sources
  - View all used loaded sources if supported by adapter.
- Modules
  - View all used modules (if adapter supports this)
- Variables
  - Copy value
  - Copy name
  - Copy memory reference
  - Set value (if adapter supports this)
  - keyboard navigation
- Debug Console
  - See logs
  - View output that was sent from debug adapter
    - Output grouping
  - Evaluate code
    - Updates the variable list
    - Auto completion
- If not supported by adapter, we will show auto-completion for existing
variables
- Debug Terminal
- Run custom commands and change env values right inside your Zed
terminal
- Attach to process (if adapter supports this)
  - Process picker
- Controls
  - Continue
  - Step back
    - Stepping granularity (configurable)
  - Step into
    - Stepping granularity (configurable)
  - Step over
    - Stepping granularity (configurable)
  - Step out
    - Stepping granularity (configurable)
  - Disconnect
  - Restart
  - Stop
- Warning when a debug session exited without hitting any breakpoint
- Debug view to see Adapter/RPC log messages
- Testing
  - Fake debug adapter
    - Fake requests & events

---

Release Notes:

- N/A

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Piotr Osiewicz <peterosiewicz@gmail.com>
Co-authored-by: Piotr <piotr@zed.dev>
This commit is contained in:
Remco Smits 2025-03-18 17:55:25 +01:00 committed by GitHub
parent ed4e654fdf
commit 41a60ffecf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
156 changed files with 25840 additions and 451 deletions

View file

@ -13,9 +13,11 @@ path = "src/tasks_ui.rs"
[dependencies]
anyhow.workspace = true
debugger_ui.workspace = true
editor.workspace = true
file_icons.workspace = true
fuzzy.workspace = true
feature_flags.workspace = true
gpui.workspace = true
menu.workspace = true
picker.workspace = true

View file

@ -9,7 +9,9 @@ use gpui::{
};
use picker::{highlighted_match_with_paths::HighlightedMatch, Picker, PickerDelegate};
use project::{task_store::TaskStore, TaskSourceKind};
use task::{ResolvedTask, RevealTarget, TaskContext, TaskTemplate};
use task::{
DebugRequestType, ResolvedTask, RevealTarget, TaskContext, TaskModal, TaskTemplate, TaskType,
};
use ui::{
div, h_flex, v_flex, ActiveTheme, Button, ButtonCommon, ButtonSize, Clickable, Color,
FluentBuilder as _, Icon, IconButton, IconButtonShape, IconName, IconSize, IntoElement,
@ -32,6 +34,8 @@ pub(crate) struct TasksModalDelegate {
prompt: String,
task_contexts: TaskContexts,
placeholder_text: Arc<str>,
/// If this delegate is responsible for running a scripting task or a debugger
task_modal_type: TaskModal,
}
/// Task template amendments to do before resolving the context.
@ -46,6 +50,7 @@ impl TasksModalDelegate {
task_store: Entity<TaskStore>,
task_contexts: TaskContexts,
task_overrides: Option<TaskOverrides>,
task_modal_type: TaskModal,
workspace: WeakEntity<Workspace>,
) -> Self {
let placeholder_text = if let Some(TaskOverrides {
@ -66,6 +71,7 @@ impl TasksModalDelegate {
selected_index: 0,
prompt: String::default(),
task_contexts,
task_modal_type,
task_overrides,
placeholder_text,
}
@ -130,12 +136,19 @@ impl TasksModal {
task_contexts: TaskContexts,
task_overrides: Option<TaskOverrides>,
workspace: WeakEntity<Workspace>,
task_modal_type: TaskModal,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let picker = cx.new(|cx| {
Picker::uniform_list(
TasksModalDelegate::new(task_store, task_contexts, task_overrides, workspace),
TasksModalDelegate::new(
task_store,
task_contexts,
task_overrides,
task_modal_type,
workspace,
),
window,
cx,
)
@ -203,11 +216,12 @@ impl PickerDelegate for TasksModalDelegate {
window: &mut Window,
cx: &mut Context<picker::Picker<Self>>,
) -> Task<()> {
let task_type = self.task_modal_type.clone();
cx.spawn_in(window, move |picker, mut cx| async move {
let Some(candidates) = picker
.update(&mut cx, |picker, cx| {
match &mut picker.delegate.candidates {
Some(candidates) => string_match_candidates(candidates.iter()),
Some(candidates) => string_match_candidates(candidates.iter(), task_type),
None => {
let Some(task_inventory) = picker
.delegate
@ -232,7 +246,8 @@ impl PickerDelegate for TasksModalDelegate {
let mut new_candidates = used;
new_candidates.extend(current);
let match_candidates = string_match_candidates(new_candidates.iter());
let match_candidates =
string_match_candidates(new_candidates.iter(), task_type);
let _ = picker.delegate.candidates.insert(new_candidates);
match_candidates
}
@ -281,7 +296,7 @@ impl PickerDelegate for TasksModalDelegate {
fn confirm(
&mut self,
omit_history_entry: bool,
_: &mut Window,
window: &mut Window,
cx: &mut Context<picker::Picker<Self>>,
) {
let current_match_index = self.selected_index();
@ -308,7 +323,43 @@ impl PickerDelegate for TasksModalDelegate {
self.workspace
.update(cx, |workspace, cx| {
schedule_resolved_task(workspace, task_source_kind, task, omit_history_entry, cx);
match task.task_type() {
TaskType::Script => schedule_resolved_task(
workspace,
task_source_kind,
task,
omit_history_entry,
cx,
),
TaskType::Debug(_) => {
let Some(config) = task.resolved_debug_adapter_config() else {
return;
};
let project = workspace.project().clone();
match &config.request {
DebugRequestType::Attach(attach_config)
if attach_config.process_id.is_none() =>
{
workspace.toggle_modal(window, cx, |window, cx| {
debugger_ui::attach_modal::AttachModal::new(
project,
config.clone(),
window,
cx,
)
});
}
_ => {
project.update(cx, |project, cx| {
project
.start_debug_session(config, cx)
.detach_and_log_err(cx);
});
}
}
}
};
})
.ok();
cx.emit(DismissEvent);
@ -462,7 +513,22 @@ impl PickerDelegate for TasksModalDelegate {
}
self.workspace
.update(cx, |workspace, cx| {
schedule_resolved_task(workspace, task_source_kind, task, omit_history_entry, cx);
match task.task_type() {
TaskType::Script => schedule_resolved_task(
workspace,
task_source_kind,
task,
omit_history_entry,
cx,
),
// TODO: Should create a schedule_resolved_debug_task function
// This would allow users to access to debug history and other issues
TaskType::Debug(_) => workspace.project().update(cx, |project, cx| {
project
.start_debug_session(task.resolved_debug_adapter_config().unwrap(), cx)
.detach_and_log_err(cx);
}),
};
})
.ok();
cx.emit(DismissEvent);
@ -584,9 +650,14 @@ impl PickerDelegate for TasksModalDelegate {
fn string_match_candidates<'a>(
candidates: impl Iterator<Item = &'a (TaskSourceKind, ResolvedTask)> + 'a,
task_modal_type: TaskModal,
) -> Vec<StringMatchCandidate> {
candidates
.enumerate()
.filter(|(_, (_, candidate))| match candidate.task_type() {
TaskType::Script => task_modal_type == TaskModal::ScriptModal,
TaskType::Debug(_) => task_modal_type == TaskModal::DebugModal,
})
.map(|(index, (_, candidate))| StringMatchCandidate::new(index, candidate.display_label()))
.collect()
}

View file

@ -3,12 +3,13 @@ use std::path::Path;
use ::settings::Settings;
use editor::Editor;
use feature_flags::{Debugger, FeatureFlagViewExt};
use gpui::{App, AppContext as _, Context, Entity, Task, Window};
use modal::{TaskOverrides, TasksModal};
use project::{Location, TaskContexts, Worktree};
use task::{RevealTarget, TaskContext, TaskId, TaskVariables, VariableName};
use task::{RevealTarget, TaskContext, TaskId, TaskModal, TaskVariables, VariableName};
use workspace::tasks::schedule_task;
use workspace::{tasks::schedule_resolved_task, Workspace};
use workspace::{tasks::schedule_resolved_task, Start, Workspace};
mod modal;
mod settings;
@ -18,7 +19,7 @@ pub use modal::{Rerun, Spawn};
pub fn init(cx: &mut App) {
settings::TaskSettings::register(cx);
cx.observe_new(
|workspace: &mut Workspace, _window: Option<&mut Window>, _: &mut Context<Workspace>| {
|workspace: &mut Workspace, window: Option<&mut Window>, cx: &mut Context<Workspace>| {
workspace
.register_action(spawn_task_or_modal)
.register_action(move |workspace, action: &modal::Rerun, window, cx| {
@ -85,9 +86,20 @@ pub fn init(cx: &mut App) {
);
}
} else {
toggle_modal(workspace, None, window, cx).detach();
toggle_modal(workspace, None, TaskModal::ScriptModal, window, cx).detach();
};
});
let Some(window) = window else {
return;
};
cx.when_flag_enabled::<Debugger>(window, |workspace, _, _| {
workspace.register_action(|workspace: &mut Workspace, _: &Start, window, cx| {
crate::toggle_modal(workspace, None, task::TaskModal::DebugModal, window, cx)
.detach();
});
});
},
)
.detach();
@ -109,15 +121,21 @@ fn spawn_task_or_modal(
});
spawn_task_with_name(task_name.clone(), overrides, window, cx).detach_and_log_err(cx)
}
Spawn::ViaModal { reveal_target } => {
toggle_modal(workspace, *reveal_target, window, cx).detach()
}
Spawn::ViaModal { reveal_target } => toggle_modal(
workspace,
*reveal_target,
TaskModal::ScriptModal,
window,
cx,
)
.detach(),
}
}
fn toggle_modal(
pub fn toggle_modal(
workspace: &mut Workspace,
reveal_target: Option<RevealTarget>,
task_type: TaskModal,
window: &mut Window,
cx: &mut Context<Workspace>,
) -> Task<()> {
@ -140,6 +158,7 @@ fn toggle_modal(
reveal_target: Some(target),
}),
workspace_handle,
task_type,
window,
cx,
)