From 65adba8e1a5616629fd8d004b771e61f03005e85 Mon Sep 17 00:00:00 2001 From: Remco Smits Date: Wed, 25 Dec 2024 20:01:26 +0100 Subject: [PATCH] Move ingore breakpoints to session model --- crates/dap/src/session.rs | 11 ++++++ crates/project/src/dap_store.rs | 65 ++++++++++++++++----------------- crates/project/src/project.rs | 8 ++-- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/crates/dap/src/session.rs b/crates/dap/src/session.rs index 1729762be332ae..a2aa2c632c4892 100644 --- a/crates/dap/src/session.rs +++ b/crates/dap/src/session.rs @@ -23,6 +23,7 @@ impl DebugSessionId { pub struct DebugSession { id: DebugSessionId, + ignore_breakpoints: bool, configuration: DebugAdapterConfig, capabilities: HashMap, clients: HashMap>, @@ -33,6 +34,7 @@ impl DebugSession { Self { id, configuration, + ignore_breakpoints: false, clients: HashMap::default(), capabilities: HashMap::default(), } @@ -50,6 +52,15 @@ impl DebugSession { &self.configuration } + pub fn ignore_breakpoints(&self) -> bool { + self.ignore_breakpoints + } + + pub fn set_ignore_breakpoints(&mut self, ignore: bool, cx: &mut ModelContext) { + self.ignore_breakpoints = ignore; + cx.notify(); + } + pub fn update_configuration( &mut self, f: impl FnOnce(&mut DebugAdapterConfig), diff --git a/crates/project/src/dap_store.rs b/crates/project/src/dap_store.rs index f23052ff8063b3..e92f818a5ed6ca 100644 --- a/crates/project/src/dap_store.rs +++ b/crates/project/src/dap_store.rs @@ -31,7 +31,6 @@ use futures::future::Shared; use futures::FutureExt; use gpui::{AsyncAppContext, Context, EventEmitter, Model, ModelContext, SharedString, Task}; use http_client::HttpClient; -use itertools::Itertools; use language::{ proto::{deserialize_anchor, serialize_anchor as serialize_text_anchor}, Buffer, BufferSnapshot, LanguageRegistry, LanguageServerBinaryStatus, @@ -99,7 +98,6 @@ pub struct DapStore { next_client_id: AtomicUsize, next_session_id: AtomicUsize, downstream_client: Option<(AnyProtoClient, u64)>, - ignore_breakpoints: HashSet, breakpoints: BTreeMap>, client_by_session: HashMap, active_debug_line: Option<(DebugAdapterClientId, ProjectPath, u32)>, @@ -148,7 +146,6 @@ impl DapStore { next_client_id: Default::default(), next_session_id: Default::default(), client_by_session: Default::default(), - ignore_breakpoints: Default::default(), } } @@ -168,7 +165,6 @@ impl DapStore { next_client_id: Default::default(), next_session_id: Default::default(), client_by_session: Default::default(), - ignore_breakpoints: Default::default(), } } @@ -333,13 +329,21 @@ impl DapStore { &self.breakpoints } - pub fn ignore_breakpoints(&self, client_id: &DebugAdapterClientId) -> bool { - self.ignore_breakpoints.contains(client_id) + pub fn ignore_breakpoints(&self, session_id: &DebugSessionId, cx: &ModelContext) -> bool { + self.session_by_id(session_id) + .map(|session| session.read(cx).ignore_breakpoints()) + .unwrap_or_default() } - pub fn toggle_ignore_breakpoints(&mut self, client_id: &DebugAdapterClientId) { - if !self.ignore_breakpoints.remove(client_id) { - self.ignore_breakpoints.insert(*client_id); + pub fn toggle_ignore_breakpoints( + &mut self, + session_id: &DebugSessionId, + cx: &mut ModelContext, + ) { + if let Some(session) = self.session_by_id(session_id) { + session.update(cx, |session, cx| { + session.set_ignore_breakpoints(!session.ignore_breakpoints(), cx); + }); } } @@ -462,9 +466,7 @@ impl DapStore { .await?; dap_store.update(&mut cx, |store, cx| { - store - .client_by_session - .insert(client_id.clone(), session_id.clone()); + store.client_by_session.insert(client_id, session_id); let session = store.session_by_id(&session_id).unwrap(); @@ -603,7 +605,7 @@ impl DapStore { let client_id = client.id(); store.client_by_session.insert(client_id, session_id); store - .as_local() + .as_local_mut() .unwrap() .sessions .insert(session_id, session.clone()); @@ -1413,7 +1415,6 @@ impl DapStore { cx.emit(DapStoreEvent::DebugClientShutdown(*client_id)); - self.ignore_breakpoints.remove(client_id); let capabilities = session.read(cx).capabilities(client_id); if let Some((downstream_client, project_id)) = self.downstream_client.as_ref() { @@ -1701,18 +1702,6 @@ impl DapStore { buffer_snapshot: BufferSnapshot, cx: &mut ModelContext, ) -> Task> { - let clients: Vec<_> = self - .as_local() - .unwrap() - .sessions - .values() - .flat_map(|session| session.read(cx).clients().collect_vec()) - .collect(); - - if clients.is_empty() { - return Task::ready(Ok(())); - } - let Some(breakpoints) = self.breakpoints.get(project_path) else { return Task::ready(Ok(())); }; @@ -1723,14 +1712,22 @@ impl DapStore { .collect::>(); let mut tasks = Vec::new(); - for client in clients { - tasks.push(self.send_breakpoints( - &client.id(), - Arc::from(buffer_path.clone()), - source_breakpoints.clone(), - self.ignore_breakpoints(&client.id()), - cx, - )); + for session in self.as_local().unwrap().sessions.values() { + let session = session.read(cx); + let ignore_breakpoints = self.ignore_breakpoints(&session.id(), cx); + for client in session.clients().collect::>() { + tasks.push(self.send_breakpoints( + &client.id(), + Arc::from(buffer_path.clone()), + source_breakpoints.clone(), + ignore_breakpoints, + cx, + )); + } + } + + if tasks.is_empty() { + return Task::ready(Ok(())); } cx.background_executor().spawn(async move { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 28f651f7b93269..2ce5178f3f9fb7 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1242,6 +1242,7 @@ impl Project { pub fn send_breakpoints( &self, + session_id: &DebugSessionId, client_id: &DebugAdapterClientId, cx: &mut ModelContext, ) -> Task<()> { @@ -1258,7 +1259,7 @@ impl Project { client_id, abs_path, source_breakpoints, - store.ignore_breakpoints(client_id), + store.ignore_breakpoints(session_id, cx), cx, ) })); @@ -1356,11 +1357,12 @@ impl Project { pub fn toggle_ignore_breakpoints( &self, + session_id: &DebugSessionId, client_id: &DebugAdapterClientId, cx: &mut ModelContext, ) -> Task> { let tasks = self.dap_store.update(cx, |store, cx| { - store.toggle_ignore_breakpoints(client_id); + store.toggle_ignore_breakpoints(session_id, cx); let mut tasks = Vec::new(); @@ -1389,7 +1391,7 @@ impl Project { .into_iter() .map(|breakpoint| breakpoint.to_source_breakpoint(buffer)) .collect::>(), - store.ignore_breakpoints(client_id), + store.ignore_breakpoints(session_id, cx), cx, ), );