Skip to content

Commit

Permalink
Move capabilities back to dapstore itself
Browse files Browse the repository at this point in the history
  • Loading branch information
RemcoSmitsDev committed Dec 25, 2024
1 parent bf293f9 commit 4730d13
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 160 deletions.
25 changes: 0 additions & 25 deletions crates/dap/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Result;
use collections::HashMap;
use dap_types::Capabilities;
use gpui::{ModelContext, Task};
use std::sync::Arc;
use task::DebugAdapterConfig;
Expand All @@ -25,7 +24,6 @@ pub struct DebugSession {
id: DebugSessionId,
ignore_breakpoints: bool,
configuration: DebugAdapterConfig,
capabilities: HashMap<DebugAdapterClientId, Capabilities>,
clients: HashMap<DebugAdapterClientId, Arc<DebugAdapterClient>>,
}

Expand All @@ -36,7 +34,6 @@ impl DebugSession {
configuration,
ignore_breakpoints: false,
clients: HashMap::default(),
capabilities: HashMap::default(),
}
}

Expand Down Expand Up @@ -70,28 +67,6 @@ impl DebugSession {
cx.notify();
}

pub fn capabilities(&self, client_id: &DebugAdapterClientId) -> Capabilities {
self.capabilities
.get(client_id)
.cloned()
.unwrap_or_default()
}

pub fn update_capabilities(
&mut self,
client_id: &DebugAdapterClientId,
new_capabilities: Capabilities,
cx: &mut ModelContext<Self>,
) {
if let Some(capabilities) = self.capabilities.get_mut(client_id) {
*capabilities = capabilities.merge(new_capabilities);
} else {
self.capabilities.insert(*client_id, new_capabilities);
}

cx.notify();
}

pub fn add_client(&mut self, client: Arc<DebugAdapterClient>, cx: &mut ModelContext<Self>) {
self.clients.insert(client.id(), client);
cx.notify();
Expand Down
15 changes: 7 additions & 8 deletions crates/debugger_ui/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,13 @@ impl CompletionProvider for ConsoleQueryBarCompletionProvider {
return Task::ready(Ok(Vec::new()));
};

let support_completions = console.update(cx, |this, cx| {
this.dap_store
.update(cx, |store, cx| {
store.capabilities_by_id(&this.client_id, cx)
})
.supports_completions_request
.unwrap_or_default()
});
let support_completions = console
.read(cx)
.dap_store
.read(cx)
.capabilities_by_id(&console.read(cx).client_id)
.supports_completions_request
.unwrap_or_default();

if support_completions {
self.client_completions(&console, buffer, buffer_position, cx)
Expand Down
7 changes: 4 additions & 3 deletions crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl DebugPanel {
Events::Module(event) => self.handle_module_event(&client_id, event, cx),
Events::LoadedSource(event) => self.handle_loaded_source_event(&client_id, event, cx),
Events::Capabilities(event) => {
self.handle_capabilities_changed_event(client_id, event, cx);
self.handle_capabilities_changed_event(session_id, client_id, event, cx);
}
Events::Memory(_) => {}
Events::Process(_) => {}
Expand All @@ -582,7 +582,7 @@ impl DebugPanel {
) {
if let Some(capabilities) = capabilities {
self.dap_store.update(cx, |store, cx| {
store.merge_capabilities_for_client(&client_id, capabilities, cx);
store.merge_capabilities_for_client(&session_id, &client_id, capabilities, cx);
});

cx.emit(DebugPanelEvent::CapabilitiesChanged(*client_id));
Expand Down Expand Up @@ -917,12 +917,13 @@ impl DebugPanel {

fn handle_capabilities_changed_event(
&mut self,
session_id: &DebugSessionId,
client_id: &DebugAdapterClientId,
event: &CapabilitiesEvent,
cx: &mut ViewContext<Self>,
) {
self.dap_store.update(cx, |store, cx| {
store.merge_capabilities_for_client(client_id, &event.capabilities, cx);
store.merge_capabilities_for_client(session_id, client_id, &event.capabilities, cx);
});

cx.emit(DebugPanelEvent::CapabilitiesChanged(*client_id));
Expand Down
29 changes: 13 additions & 16 deletions crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,20 +428,19 @@ impl DebugPanelItem {
return;
}

self.dap_store.update(cx, |dap_store, cx| {
if let Some((downstream_client, project_id)) = dap_store.downstream_client() {
let message = proto_conversions::capabilities_to_proto(
&dap_store.capabilities_by_id(client_id, cx),
*project_id,
self.session_id.to_proto(),
self.client_id.to_proto(),
);

downstream_client.send(message).log_err();
}
});

// notify the view that the capabilities have changed
cx.notify();

if let Some((downstream_client, project_id)) = self.dap_store.read(cx).downstream_client() {
let message = proto_conversions::capabilities_to_proto(
&self.dap_store.read(cx).capabilities_by_id(client_id),
*project_id,
self.session_id.to_proto(),
self.client_id.to_proto(),
);

downstream_client.send(message).log_err();
}
}

pub(crate) fn update_adapter(
Expand Down Expand Up @@ -502,9 +501,7 @@ impl DebugPanelItem {
}

pub fn capabilities(&self, cx: &mut ViewContext<Self>) -> Capabilities {
self.dap_store.update(cx, |store, cx| {
store.capabilities_by_id(&self.client_id, cx)
})
self.dap_store.read(cx).capabilities_by_id(&self.client_id)
}

fn clear_highlights(&self, cx: &mut ViewContext<Self>) {
Expand Down
12 changes: 6 additions & 6 deletions crates/debugger_ui/src/variable_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,12 @@ impl VariableList {
) {
let this = cx.view().clone();

let support_set_variable = self.dap_store.update(cx, |store, cx| {
store
.capabilities_by_id(&self.client_id, cx)
.supports_set_variable
.unwrap_or_default()
});
let support_set_variable = self
.dap_store
.read(cx)
.capabilities_by_id(&self.client_id)
.supports_set_variable
.unwrap_or_default();

let context_menu = ContextMenu::build(cx, |menu, cx| {
menu.entry(
Expand Down
Loading

0 comments on commit 4730d13

Please sign in to comment.