Files
zed/crates/debugger_ui/src/loaded_source_list.rs
Remco Smits ecfc0ef12d Move requests into client (#112)
* Move most of the requests into the client state itself.

Co-authored-by: Anthony Eid <hello@anthonyeid.me>

* WIP

* Fix some errors and create new errors

* More teardown

* Fix detach requests

* Move set variable value to dap command

* Fix dap command error and add evaluate command

* FIx more compiler errors

* Fix more compiler errors

* Clipppyyyy

* FIx more

* One more

* Fix one more

* Use threadId from project instead u64

* Mostly fix stack frame list

* More compile errors

* More

* WIP transfer completions to dap command

Co-Authored-By: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
Co-Authored-By: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>

* Finish console completions DapCommand impl

* Get Zed to build !!

* Fix test compile errors: The debugger tests will still fail

* Add threads reqeust to debug session

Co-authored-by: Piotr Osiewicz <piotr@zed.dev>

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
Co-authored-by: Piotr Osiewicz <piotr@zed.dev>
2025-02-13 16:25:32 -05:00

108 lines
3.2 KiB
Rust

use dap::client::DebugAdapterClientId;
use gpui::{list, AnyElement, Empty, Entity, FocusHandle, Focusable, ListState, Subscription};
use project::debugger::dap_session::DebugSession;
use ui::prelude::*;
use util::maybe;
pub struct LoadedSourceList {
list: ListState,
focus_handle: FocusHandle,
_subscription: Subscription,
session: Entity<DebugSession>,
client_id: DebugAdapterClientId,
}
impl LoadedSourceList {
pub fn new(
session: Entity<DebugSession>,
client_id: DebugAdapterClientId,
cx: &mut Context<Self>,
) -> Self {
let weak_entity = cx.weak_entity();
let focus_handle = cx.focus_handle();
let list = ListState::new(
0,
gpui::ListAlignment::Top,
px(1000.),
move |ix, _window, cx| {
weak_entity
.upgrade()
.map(|loaded_sources| {
loaded_sources.update(cx, |this, cx| this.render_entry(ix, cx))
})
.unwrap_or(div().into_any())
},
);
let client_state = session.read(cx).client_state(client_id).unwrap();
let _subscription = cx.observe(&client_state, |loaded_source_list, state, cx| {
let len = state.update(cx, |state, cx| state.loaded_sources(cx).len());
loaded_source_list.list.reset(len);
cx.notify();
});
Self {
list,
session,
focus_handle,
_subscription,
client_id,
}
}
fn render_entry(&mut self, ix: usize, cx: &mut Context<Self>) -> AnyElement {
let Some(source) = maybe!({
self.session
.read(cx)
.client_state(self.client_id)?
.update(cx, |state, cx| state.loaded_sources(cx).get(ix).cloned())
}) else {
return Empty.into_any();
};
v_flex()
.rounded_md()
.w_full()
.group("")
.p_1()
.hover(|s| s.bg(cx.theme().colors().element_hover))
.child(
h_flex()
.gap_0p5()
.text_ui_sm(cx)
.when_some(source.name.clone(), |this, name| this.child(name)),
)
.child(
h_flex()
.text_ui_xs(cx)
.text_color(cx.theme().colors().text_muted)
.when_some(source.path.clone(), |this, path| this.child(path)),
)
.into_any()
}
}
impl Focusable for LoadedSourceList {
fn focus_handle(&self, _: &gpui::App) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
impl Render for LoadedSourceList {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
if let Some(state) = self.session.read(cx).client_state(self.client_id) {
state.update(cx, |state, cx| {
state.loaded_sources(cx);
});
}
div()
.track_focus(&self.focus_handle)
.size_full()
.p_1()
.child(list(self.list.clone()).size_full())
}
}