Skip to content

Commit

Permalink
Move sessions to local dap store
Browse files Browse the repository at this point in the history
  • Loading branch information
RemcoSmitsDev committed Dec 25, 2024
1 parent d99a0ae commit 0be524a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub enum DapStoreMode {
pub struct LocalDapStore {
delegate: DapAdapterDelegate,
environment: Model<ProjectEnvironment>,
sessions: HashMap<DebugSessionId, Model<DebugSession>>,
}

pub struct RemoteDapStore {
Expand All @@ -99,7 +100,6 @@ pub struct DapStore {
next_session_id: AtomicUsize,
downstream_client: Option<(AnyProtoClient, u64)>,
ignore_breakpoints: HashSet<DebugAdapterClientId>,
sessions: HashMap<DebugSessionId, Model<DebugSession>>,
breakpoints: BTreeMap<ProjectPath, HashSet<Breakpoint>>,
client_by_session: HashMap<DebugAdapterClientId, DebugSessionId>,
active_debug_line: Option<(DebugAdapterClientId, ProjectPath, u32)>,
Expand Down Expand Up @@ -140,10 +140,10 @@ impl DapStore {
languages.clone(),
Task::ready(None).shared(),
),
sessions: HashMap::default(),
}),
downstream_client: None,
active_debug_line: None,
sessions: HashMap::default(),
breakpoints: Default::default(),
next_client_id: Default::default(),
next_session_id: Default::default(),
Expand All @@ -164,7 +164,6 @@ impl DapStore {
}),
downstream_client: None,
active_debug_line: None,
sessions: HashMap::default(),
breakpoints: Default::default(),
next_client_id: Default::default(),
next_session_id: Default::default(),
Expand Down Expand Up @@ -223,11 +222,11 @@ impl DapStore {
}

pub fn sessions(&self) -> impl Iterator<Item = Model<DebugSession>> + '_ {
self.sessions.values().cloned()
self.as_local().unwrap().sessions.values().cloned()
}

pub fn session_by_id(&self, session_id: &DebugSessionId) -> Option<Model<DebugSession>> {
self.sessions.get(session_id).cloned()
self.as_local().unwrap().sessions.get(session_id).cloned()
}

pub fn client_by_id(
Expand All @@ -236,6 +235,8 @@ impl DapStore {
cx: &mut ModelContext<Self>,
) -> Option<(Model<DebugSession>, Arc<DebugAdapterClient>)> {
let session = self
.as_local()
.unwrap()
.sessions
.get(self.client_by_session.get(client_id)?)
.cloned()?;
Expand Down Expand Up @@ -601,7 +602,11 @@ impl DapStore {

let client_id = client.id();
store.client_by_session.insert(client_id, session_id);
store.sessions.insert(session_id, session.clone());
store
.as_local()
.unwrap()
.sessions
.insert(session_id, session.clone());

cx.emit(DapStoreEvent::DebugClientStarted((session_id, client_id)));
cx.notify();
Expand Down Expand Up @@ -1362,7 +1367,14 @@ impl DapStore {
pub fn shutdown_sessions(&mut self, cx: &mut ModelContext<Self>) -> Task<()> {
let mut tasks = Vec::new();

for session_id in self.sessions.keys().cloned().collect::<Vec<_>>() {
for session_id in self
.as_local()
.unwrap()
.sessions
.keys()
.cloned()
.collect::<Vec<_>>()
{
tasks.push(self.shutdown_session(&session_id, cx));
}

Expand All @@ -1376,7 +1388,7 @@ impl DapStore {
session_id: &DebugSessionId,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
let Some(session) = self.sessions.remove(session_id) else {
let Some(session) = self.as_local_mut().unwrap().sessions.remove(session_id) else {
return Task::ready(Err(anyhow!("Could not find session: {:?}", session_id)));
};

Expand Down Expand Up @@ -1690,6 +1702,8 @@ impl DapStore {
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
let clients: Vec<_> = self
.as_local()
.unwrap()
.sessions
.values()
.flat_map(|session| session.read(cx).clients().collect_vec())
Expand Down

0 comments on commit 0be524a

Please sign in to comment.