Skip to content

Commit

Permalink
Move ingore breakpoints to session model
Browse files Browse the repository at this point in the history
  • Loading branch information
RemcoSmitsDev committed Dec 25, 2024
1 parent 0be524a commit 65adba8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
11 changes: 11 additions & 0 deletions crates/dap/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl DebugSessionId {

pub struct DebugSession {
id: DebugSessionId,
ignore_breakpoints: bool,
configuration: DebugAdapterConfig,
capabilities: HashMap<DebugAdapterClientId, Capabilities>,
clients: HashMap<DebugAdapterClientId, Arc<DebugAdapterClient>>,
Expand All @@ -33,6 +34,7 @@ impl DebugSession {
Self {
id,
configuration,
ignore_breakpoints: false,
clients: HashMap::default(),
capabilities: HashMap::default(),
}
Expand All @@ -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>) {
self.ignore_breakpoints = ignore;
cx.notify();
}

pub fn update_configuration(
&mut self,
f: impl FnOnce(&mut DebugAdapterConfig),
Expand Down
65 changes: 31 additions & 34 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,7 +98,6 @@ pub struct DapStore {
next_client_id: AtomicUsize,
next_session_id: AtomicUsize,
downstream_client: Option<(AnyProtoClient, u64)>,
ignore_breakpoints: HashSet<DebugAdapterClientId>,
breakpoints: BTreeMap<ProjectPath, HashSet<Breakpoint>>,
client_by_session: HashMap<DebugAdapterClientId, DebugSessionId>,
active_debug_line: Option<(DebugAdapterClientId, ProjectPath, u32)>,
Expand Down Expand Up @@ -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(),
}
}

Expand All @@ -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(),
}
}

Expand Down Expand Up @@ -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<Self>) -> 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<Self>,
) {
if let Some(session) = self.session_by_id(session_id) {
session.update(cx, |session, cx| {
session.set_ignore_breakpoints(!session.ignore_breakpoints(), cx);
});
}
}

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -1701,18 +1702,6 @@ impl DapStore {
buffer_snapshot: BufferSnapshot,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
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(()));
};
Expand All @@ -1723,14 +1712,22 @@ impl DapStore {
.collect::<Vec<_>>();

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::<Vec<_>>() {
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 {
Expand Down
8 changes: 5 additions & 3 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ impl Project {

pub fn send_breakpoints(
&self,
session_id: &DebugSessionId,
client_id: &DebugAdapterClientId,
cx: &mut ModelContext<Self>,
) -> Task<()> {
Expand All @@ -1258,7 +1259,7 @@ impl Project {
client_id,
abs_path,
source_breakpoints,
store.ignore_breakpoints(client_id),
store.ignore_breakpoints(session_id, cx),
cx,
)
}));
Expand Down Expand Up @@ -1356,11 +1357,12 @@ impl Project {

pub fn toggle_ignore_breakpoints(
&self,
session_id: &DebugSessionId,
client_id: &DebugAdapterClientId,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
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();

Expand Down Expand Up @@ -1389,7 +1391,7 @@ impl Project {
.into_iter()
.map(|breakpoint| breakpoint.to_source_breakpoint(buffer))
.collect::<Vec<_>>(),
store.ignore_breakpoints(client_id),
store.ignore_breakpoints(session_id, cx),
cx,
),
);
Expand Down

0 comments on commit 65adba8

Please sign in to comment.