use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StepInTargetsAsk {
Sent,
Unsupported,
NoFrame,
}
pub fn thread_request(command: &str, thread_id: i64) -> Value {
json!({
"type": "request",
"command": command,
"arguments": { "threadId": thread_id }
})
}
pub fn step_in_targets_request(frame_id: i64) -> Value {
json!({
"type": "request",
"command": "stepInTargets",
"arguments": { "frameId": frame_id }
})
}
pub fn step_in_target_request(thread_id: i64, target_id: i64) -> Value {
json!({
"type": "request",
"command": "stepIn",
"arguments": { "threadId": thread_id, "targetId": target_id }
})
}
pub fn parse_step_in_targets(msg: &Value) -> Vec<(i64, String)> {
msg.pointer("/body/targets")
.and_then(Value::as_array)
.map(|ts| {
ts.iter()
.filter_map(|t| {
Some((
t.get("id")?.as_i64()?,
t.get("label")?.as_str()?.to_string(),
))
})
.collect()
})
.unwrap_or_default()
}
impl DapSession {
pub fn pause(&mut self) {
if let Some(tid) = self.stopped_thread.or(self.known_thread) {
let _ = self.active().send(thread_request("pause", tid));
}
}
pub fn continue_execution(&mut self) {
if let Some(tid) = self.stopped_thread {
let _ = self.active().send(thread_request("continue", tid));
self.phase = SessionPhase::Running;
self.exception_info_seq = None;
self.step_in_targets_seq = None;
}
}
pub fn step(&mut self, command: &str) {
if let Some(tid) = self.stopped_thread {
let _ = self.active().send(thread_request(command, tid));
self.exception_info_seq = None;
self.step_in_targets_seq = None;
}
}
pub fn request_step_in_targets(&mut self) -> StepInTargetsAsk {
if self.phase != SessionPhase::Stopped || !self.supports("supportsStepInTargetsRequest") {
return StepInTargetsAsk::Unsupported;
}
let Some(frame) = self
.selected_frame
.or_else(|| self.stack_frames.first().map(|f| f.id))
else {
return StepInTargetsAsk::NoFrame;
};
self.step_in_targets_seq = self.active().send(step_in_targets_request(frame)).ok();
if self.step_in_targets_seq.is_some() {
StepInTargetsAsk::Sent
} else {
StepInTargetsAsk::NoFrame
}
}
pub fn step_in_target(&mut self, target_id: i64) {
if let Some(tid) = self.stopped_thread {
let _ = self.active().send(step_in_target_request(tid, target_id));
self.exception_info_seq = None;
self.step_in_targets_seq = None;
}
}
}