debugger: Add run to cursor and evaluate selected text actions (#28405)
## Summary ### Actions This PR implements actions that allow a user to "run to cursor" and "evaluate selected text" while there's an active debug session and exposes the functionality to the UI as well. - Run to cursor: Can be accessed by right clicking on the gutter - Evaluate selected text: Can be accessed by selecting text then right clicking in the editor ### Bug fixes I also fixed these bugs as well - Panic when using debugger: Stop action - Debugger actions command palette filter not working properly in all cases - We stopped displaying the correct label in the session's context menu when a session was terminated Release Notes: - N/A --------- Co-authored-by: Max Brunsfeld <max@zed.dev> Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
parent
780143298a
commit
2752c08810
15 changed files with 334 additions and 102 deletions
|
@ -1,5 +1,7 @@
|
|||
pub mod running;
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use dap::client::SessionId;
|
||||
use gpui::{App, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Task, WeakEntity};
|
||||
use project::Project;
|
||||
|
@ -30,6 +32,7 @@ impl DebugSessionState {
|
|||
pub struct DebugSession {
|
||||
remote_id: Option<workspace::ViewId>,
|
||||
mode: DebugSessionState,
|
||||
label: OnceLock<String>,
|
||||
dap_store: WeakEntity<DapStore>,
|
||||
_debug_panel: WeakEntity<DebugPanel>,
|
||||
_worktree_store: WeakEntity<WorktreeStore>,
|
||||
|
@ -68,6 +71,7 @@ impl DebugSession {
|
|||
})],
|
||||
remote_id: None,
|
||||
mode: DebugSessionState::Running(mode),
|
||||
label: OnceLock::new(),
|
||||
dap_store: project.read(cx).dap_store().downgrade(),
|
||||
_debug_panel,
|
||||
_worktree_store: project.read(cx).worktree_store().downgrade(),
|
||||
|
@ -92,36 +96,45 @@ impl DebugSession {
|
|||
}
|
||||
|
||||
pub(crate) fn label(&self, cx: &App) -> String {
|
||||
if let Some(label) = self.label.get() {
|
||||
return label.to_owned();
|
||||
}
|
||||
|
||||
let session_id = match &self.mode {
|
||||
DebugSessionState::Running(running_state) => running_state.read(cx).session_id(),
|
||||
};
|
||||
|
||||
let Ok(Some(session)) = self
|
||||
.dap_store
|
||||
.read_with(cx, |store, _| store.session_by_id(session_id))
|
||||
else {
|
||||
return "".to_owned();
|
||||
};
|
||||
session
|
||||
.read(cx)
|
||||
.as_local()
|
||||
.expect("Remote Debug Sessions are not implemented yet")
|
||||
.label()
|
||||
|
||||
self.label
|
||||
.get_or_init(|| {
|
||||
session
|
||||
.read(cx)
|
||||
.as_local()
|
||||
.expect("Remote Debug Sessions are not implemented yet")
|
||||
.label()
|
||||
})
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
pub(crate) fn label_element(&self, cx: &App) -> AnyElement {
|
||||
let label = self.label(cx);
|
||||
|
||||
let (icon, color) = match &self.mode {
|
||||
let icon = match &self.mode {
|
||||
DebugSessionState::Running(state) => {
|
||||
if state.read(cx).session().read(cx).is_terminated() {
|
||||
(Some(Indicator::dot().color(Color::Error)), Color::Error)
|
||||
Some(Indicator::dot().color(Color::Error))
|
||||
} else {
|
||||
match state.read(cx).thread_status(cx).unwrap_or_default() {
|
||||
project::debugger::session::ThreadStatus::Stopped => (
|
||||
Some(Indicator::dot().color(Color::Conflict)),
|
||||
Color::Conflict,
|
||||
),
|
||||
_ => (Some(Indicator::dot().color(Color::Success)), Color::Success),
|
||||
project::debugger::session::ThreadStatus::Stopped => {
|
||||
Some(Indicator::dot().color(Color::Conflict))
|
||||
}
|
||||
_ => Some(Indicator::dot().color(Color::Success)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +144,7 @@ impl DebugSession {
|
|||
.gap_2()
|
||||
.when_some(icon, |this, indicator| this.child(indicator))
|
||||
.justify_between()
|
||||
.child(Label::new(label).color(color))
|
||||
.child(Label::new(label))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue