use super::*;
pub fn is_debug_test_config(cfg: &DebugConfig) -> bool {
let debug_test = match cfg.raw.get("purpose") {
Some(Value::String(s)) => s == "debug-test",
Some(Value::Array(list)) => list.iter().any(|v| v.as_str() == Some("debug-test")),
_ => false,
};
debug_test && adapter_for_type(&cfg.type_name) == Some(AdapterKind::Debugpy)
}
pub fn debug_test_config(configs: &[DebugConfig]) -> Option<&DebugConfig> {
configs.iter().find(|c| is_debug_test_config(c))
}
pub(super) const DEBUG_TEST_META_KEYS: &[&str] = &["purpose", "presentation"];
pub fn with_debug_test_config(mut request: Value, rc: &ResolvedConfig) -> Value {
let Some(args) = request["arguments"].as_object_mut() else {
return request;
};
for (key, value) in &rc.extra {
if !DEBUG_TEST_META_KEYS.contains(&key.as_str()) {
args.insert(key.clone(), value.clone());
}
}
if !rc.env.is_empty() {
args.insert("env".into(), json!(rc.env));
}
if let Some(cwd) = &rc.cwd {
args.insert("cwd".into(), json!(cwd.to_string_lossy()));
}
if let Some(list) = args.get_mut("args").and_then(Value::as_array_mut) {
list.extend(rc.args.iter().map(|a| json!(a)));
}
if rc.stop_on_entry {
args.insert("stopOnEntry".into(), json!(true));
}
request
}