Clear breakpoints action (#27254)

This PR adds an action that clears all breakpoints and notifies any
active DAPs.

todo
- [x] Implement clear functionality
- [x] Write an integration test for this

Release Notes:

- N/A *or* Added/Fixed/Improved ...

---------

Co-authored-by: Piotr Osiewicz <peterosiewicz@gmail.com>
This commit is contained in:
Anthony Eid 2025-03-21 16:18:08 -04:00 committed by GitHub
parent 16ad7424d6
commit 739f45eb23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 209 additions and 5 deletions

View file

@ -5,7 +5,7 @@ use anyhow::{anyhow, Result};
use breakpoints_in_file::BreakpointsInFile;
use collections::BTreeMap;
use dap::client::SessionId;
use gpui::{App, AppContext, AsyncApp, Context, Entity, EventEmitter, Task};
use gpui::{App, AppContext, AsyncApp, Context, Entity, EventEmitter, Subscription, Task};
use language::{proto::serialize_anchor as serialize_text_anchor, Buffer, BufferSnapshot};
use rpc::{
proto::{self},
@ -31,7 +31,7 @@ mod breakpoints_in_file {
pub(super) buffer: Entity<Buffer>,
// TODO: This is.. less than ideal, as it's O(n) and does not return entries in order. We'll have to change TreeMap to support passing in the context for comparisons
pub(super) breakpoints: Vec<(text::Anchor, Breakpoint)>,
_subscription: Arc<gpui::Subscription>,
_subscription: Arc<Subscription>,
}
impl BreakpointsInFile {
@ -341,6 +341,12 @@ impl BreakpointStore {
}
}
pub fn clear_breakpoints(&mut self, cx: &mut Context<Self>) {
let breakpoint_paths = self.breakpoints.keys().cloned().collect();
self.breakpoints.clear();
cx.emit(BreakpointStoreEvent::BreakpointsCleared(breakpoint_paths));
}
pub fn breakpoints<'a>(
&'a self,
buffer: &'a Entity<Buffer>,
@ -498,6 +504,11 @@ impl BreakpointStore {
Task::ready(Ok(()))
}
}
#[cfg(any(test, feature = "test-support"))]
pub(crate) fn breakpoint_paths(&self) -> Vec<Arc<Path>> {
self.breakpoints.keys().cloned().collect()
}
}
#[derive(Clone, Copy)]
@ -509,6 +520,7 @@ pub enum BreakpointUpdatedReason {
pub enum BreakpointStoreEvent {
ActiveDebugLineChanged,
BreakpointsUpdated(Arc<Path>, BreakpointUpdatedReason),
BreakpointsCleared(Vec<Arc<Path>>),
}
impl EventEmitter<BreakpointStoreEvent> for BreakpointStore {}

View file

@ -237,6 +237,19 @@ impl LocalMode {
.on_request::<dap::requests::Initialize, _>(move |_, _| Ok(caps.clone()))
.await;
let paths = cx.update(|cx| session.breakpoint_store.read(cx).breakpoint_paths()).expect("Breakpoint store should exist in all tests that start debuggers");
session.client.on_request::<dap::requests::SetBreakpoints, _>(move |_, args| {
let p = Arc::from(Path::new(&args.source.path.unwrap()));
if !paths.contains(&p) {
panic!("Sent breakpoints for path without any")
}
Ok(dap::SetBreakpointsResponse {
breakpoints: Vec::default(),
})
}).await;
match config.request.clone() {
dap::DebugRequestType::Launch if fail => {
session
@ -307,6 +320,34 @@ impl LocalMode {
})
}
fn unset_breakpoints_from_paths(&self, paths: &Vec<Arc<Path>>, cx: &mut App) -> Task<()> {
let tasks: Vec<_> = paths
.into_iter()
.map(|path| {
self.request(
dap_command::SetBreakpoints {
source: client_source(path),
source_modified: None,
breakpoints: vec![],
},
cx.background_executor().clone(),
)
})
.collect();
cx.background_spawn(async move {
futures::future::join_all(tasks)
.await
.iter()
.for_each(|res| match res {
Ok(_) => {}
Err(err) => {
log::warn!("Set breakpoints request failed: {}", err);
}
});
})
}
fn send_breakpoints_from_path(
&self,
abs_path: Arc<Path>,
@ -752,6 +793,14 @@ impl Session {
.detach();
};
}
BreakpointStoreEvent::BreakpointsCleared(paths) => {
if let Some(local) = (!this.ignore_breakpoints)
.then(|| this.as_local_mut())
.flatten()
{
local.unset_breakpoints_from_paths(paths, cx).detach();
}
}
BreakpointStoreEvent::ActiveDebugLineChanged => {}
})
.detach();