Skip to content

Commit

Permalink
Send the initial breakpoints from the project
Browse files Browse the repository at this point in the history
We now send the initial breakpoints that we created before the debug adapter was running.

Co-Authored-By: Anthony Eid <[email protected]>
  • Loading branch information
RemcoSmitsDev and Anthony-Eid committed Jul 12, 2024
1 parent 68dd3c9 commit 014ffbc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
16 changes: 14 additions & 2 deletions crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,20 @@ impl DebugPanel {
match event {
Events::Initialized(_) => {
let client = this.debug_client_by_id(*client_id, cx);
cx.spawn(|_, _| async move {
// TODO: send all the current breakpoints

cx.spawn(|this, mut cx| async move {
let task = this.update(&mut cx, |this, cx| {
this.workspace.update(cx, |workspace, cx| {
workspace.project().update(cx, |project, cx| {
let client = client.clone();

project.send_breakpoints(client, cx)
})
})
})??;

task.await?;

client.configuration_done().await
})
.detach_and_log_err(cx);
Expand Down
51 changes: 51 additions & 0 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,57 @@ impl Project {
})
}

pub fn send_breakpoints(
&self,
client: Arc<DebugAdapterClient>,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
cx.spawn(|project, mut cx| async move {
let task = project.update(&mut cx, |project, cx| {
let mut tasks = Vec::new();

for (buffer_id, breakpoints) in project.breakpoints.iter() {
let res = maybe!({
let buffer = project.buffer_for_id(*buffer_id)?;

let project_path = buffer.read(cx).project_path(cx)?;
let worktree = project.worktree_for_id(project_path.worktree_id, cx)?;
let path = worktree.read(cx).absolutize(&project_path.path).ok()?;

Some((path, breakpoints))
});

if let Some((path, breakpoints)) = res {
tasks.push(
client.set_breakpoints(
path,
Some(
breakpoints
.iter()
.map(|b| SourceBreakpoint {
line: b.row as u64,
condition: None,
hit_condition: None,
log_message: None,
column: None,
mode: None,
})
.collect::<Vec<_>>(),
),
),
);
}
}

try_join_all(tasks)
})?;

task.await?;

Ok(())
})
}

pub fn start_debug_adapter_client(
&mut self,
debug_task: task::ResolvedTask,
Expand Down

0 comments on commit 014ffbc

Please sign in to comment.