From 13dd3aa2b5012355e91d7e384cea144d331faed7 Mon Sep 17 00:00:00 2001 From: Anthony Eid Date: Wed, 19 Feb 2025 02:26:00 -0500 Subject: [PATCH] Enable session to send changed breakpoints to active dap servers --- .../project/src/debugger/breakpoint_store.rs | 2 +- crates/project/src/debugger/session.rs | 64 +++++++++++++++---- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/crates/project/src/debugger/breakpoint_store.rs b/crates/project/src/debugger/breakpoint_store.rs index d24c1533e0..39edab41cb 100644 --- a/crates/project/src/debugger/breakpoint_store.rs +++ b/crates/project/src/debugger/breakpoint_store.rs @@ -424,7 +424,7 @@ impl BreakpointStore { }) } - fn serialize_breakpoints_for_project_path( + pub(crate) fn serialize_breakpoints_for_project_path( &self, project_path: &ProjectPath, cx: &App, diff --git a/crates/project/src/debugger/session.rs b/crates/project/src/debugger/session.rs index ab77d64c34..70f6eaa390 100644 --- a/crates/project/src/debugger/session.rs +++ b/crates/project/src/debugger/session.rs @@ -1,6 +1,6 @@ use crate::project_settings::ProjectSettings; -use super::breakpoint_store::{self, BreakpointStore}; +use super::breakpoint_store::{self, BreakpointStore, BreakpointStoreEvent}; use super::dap_command::{ self, ConfigurationDone, ContinueCommand, DapCommand, DisconnectCommand, EvaluateCommand, Initialize, Launch, LocalDapCommand, NextCommand, PauseCommand, RestartCommand, @@ -425,17 +425,22 @@ impl Session { ) .await?; - cx.new(|_| Self { - mode: Mode::Local(mode), - id: session_id, - breakpoint_store: breakpoints, - config, - capabilities, - ignore_breakpoints: false, - requests: HashMap::default(), - modules: Vec::default(), - loaded_sources: Vec::default(), - threads: IndexMap::default(), + cx.new(|cx| { + cx.subscribe(&breakpoints, Self::send_changed_breakpoints) + .detach(); + + Self { + mode: Mode::Local(mode), + id: session_id, + breakpoint_store: breakpoints, + config, + capabilities, + ignore_breakpoints: false, + requests: HashMap::default(), + modules: Vec::default(), + loaded_sources: Vec::default(), + threads: IndexMap::default(), + } }) }) } @@ -475,6 +480,41 @@ impl Session { self.config.clone() } + fn send_changed_breakpoints( + &mut self, + _breakpoint_store: Entity, + event: &BreakpointStoreEvent, + cx: &mut Context, + ) { + let BreakpointStoreEvent::BreakpointsChanged { + project_path, + source_changed, + } = event; + + // We still want to send an empty list of breakpoints to tell the dap server that there are no breakpoints + let Some((abs_path, breakpoints)) = self + .breakpoint_store + .read(cx) + .serialize_breakpoints_for_project_path(project_path, cx) + else { + return; + }; + + let source_breakpoints = breakpoints + .iter() + .map(|bp| bp.to_source_breakpoint()) + .collect::>(); + + self.send_breakpoints( + abs_path, + source_breakpoints, + self.ignore_breakpoints, + *source_changed, + cx, + ) + .detach_and_log_err(cx); + } + fn send_initial_breakpoints(&self, cx: &App) -> Task<()> { let mut tasks = Vec::new();