mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
dap: Extract a thread_states map
This commit is contained in:
parent
5b920c53f0
commit
27c1b3f98b
@ -31,6 +31,7 @@ pub struct Client {
|
||||
pub breakpoints: HashMap<PathBuf, Vec<SourceBreakpoint>>,
|
||||
// thread_id -> frames
|
||||
pub stack_frames: HashMap<usize, Vec<StackFrame>>,
|
||||
pub thread_states: HashMap<usize, String>,
|
||||
pub thread_id: Option<usize>,
|
||||
/// Currently active frame for the current thread.
|
||||
pub active_frame: Option<usize>,
|
||||
|
@ -273,10 +273,12 @@ pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
|
||||
all_threads_stopped,
|
||||
..
|
||||
}) => {
|
||||
debugger.is_running = false;
|
||||
if let Some(thread_id) = thread_id {
|
||||
debugger.thread_states.insert(thread_id, reason); // TODO: dap uses "type" || "reason" here
|
||||
// whichever thread stops is made "current" (if no previously selected thread).
|
||||
select_thread_id(&mut self.editor, thread_id, false).await;
|
||||
}
|
||||
|
||||
// whichever thread stops is made "current" (if no previously selected thread).
|
||||
select_thread_id(&mut self.editor, thread_id.unwrap(), false).await;
|
||||
|
||||
let scope = match thread_id {
|
||||
Some(id) => format!("Thread {}", id),
|
||||
@ -296,6 +298,15 @@ pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
|
||||
|
||||
self.editor.set_status(status);
|
||||
}
|
||||
Event::Continued(events::Continued { thread_id, .. }) => {
|
||||
debugger.thread_states.remove(&thread_id);
|
||||
if debugger.thread_id == Some(thread_id) {
|
||||
resume_application(debugger)
|
||||
}
|
||||
}
|
||||
Event::Thread(_) => {
|
||||
// TODO: update thread_states, make threads request
|
||||
}
|
||||
Event::Output(events::Output {
|
||||
category, output, ..
|
||||
}) => {
|
||||
@ -315,12 +326,6 @@ pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
|
||||
self.editor
|
||||
.set_status("Debugged application started".to_owned());
|
||||
}
|
||||
Event::Continued(events::Continued { thread_id, .. }) => {
|
||||
// TODO: remove thread from thread-states
|
||||
if debugger.thread_id == Some(thread_id) {
|
||||
resume_application(debugger)
|
||||
}
|
||||
}
|
||||
ev => {
|
||||
log::warn!("Unhandled event {:?}", ev);
|
||||
return; // return early to skip render
|
||||
|
@ -19,7 +19,10 @@ pub fn dap_pos_to_pos(doc: &helix_core::Rope, line: usize, column: usize) -> Opt
|
||||
}
|
||||
|
||||
pub fn resume_application(debugger: &mut Client) {
|
||||
debugger.is_running = true; // TODO: set state running for debugger.thread_id
|
||||
if let Some(thread_id) = debugger.thread_id {
|
||||
debugger.thread_states.insert(thread_id, "running".to_string());
|
||||
debugger.stack_frames.remove(&thread_id);
|
||||
}
|
||||
debugger.active_frame = None;
|
||||
debugger.thread_id = None;
|
||||
}
|
||||
@ -302,7 +305,6 @@ pub fn dap_continue(cx: &mut Context) {
|
||||
return;
|
||||
}
|
||||
resume_application(debugger);
|
||||
debugger.stack_frames.remove(&thread_id);
|
||||
} else {
|
||||
cx.editor
|
||||
.set_error("Currently active thread is not stopped. Switch the thread.".into());
|
||||
@ -315,6 +317,8 @@ pub fn dap_pause(cx: &mut Context) {
|
||||
None => return,
|
||||
};
|
||||
|
||||
// TODO: this should instead open a picker to pause a selected thread
|
||||
|
||||
if !debugger.is_running {
|
||||
cx.editor.set_status("Debuggee is not running".to_owned());
|
||||
return;
|
||||
@ -340,7 +344,6 @@ pub fn dap_step_in(cx: &mut Context) {
|
||||
return;
|
||||
}
|
||||
resume_application(debugger);
|
||||
debugger.stack_frames.remove(&thread_id);
|
||||
} else {
|
||||
cx.editor
|
||||
.set_error("Currently active thread is not stopped. Switch the thread.".into());
|
||||
@ -360,7 +363,6 @@ pub fn dap_step_out(cx: &mut Context) {
|
||||
return;
|
||||
}
|
||||
resume_application(debugger);
|
||||
debugger.stack_frames.remove(&thread_id);
|
||||
} else {
|
||||
cx.editor
|
||||
.set_error("Currently active thread is not stopped. Switch the thread.".into());
|
||||
@ -380,7 +382,6 @@ pub fn dap_next(cx: &mut Context) {
|
||||
return;
|
||||
}
|
||||
resume_application(debugger);
|
||||
debugger.stack_frames.remove(&thread_id);
|
||||
} else {
|
||||
cx.editor
|
||||
.set_error("Currently active thread is not stopped. Switch the thread.".into());
|
||||
@ -393,7 +394,7 @@ pub fn dap_variables(cx: &mut Context) {
|
||||
None => return,
|
||||
};
|
||||
|
||||
if debugger.is_running {
|
||||
if debugger.thread_id.is_none() {
|
||||
cx.editor
|
||||
.set_status("Cannot access variables while target is running".to_owned());
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user