use super::*;
pub fn initialize_request(child_sessions: bool) -> Value {
json!({
"type": "request",
"command": "initialize",
"arguments": {
"adapterID": "debugpy",
"linesStartAt1": true,
"columnsStartAt1": true,
"pathFormat": "path",
"supportsRunInTerminalRequest": true,
"supportsStartDebuggingRequest": child_sessions
}
})
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AdapterKind {
Debugpy,
LldbDap,
JsDebug,
Delve,
}
pub fn delve_zero_config_request(file: &Path) -> Value {
let dir = file.parent().unwrap_or_else(|| Path::new("."));
let is_test = file
.file_name()
.and_then(|n| n.to_str())
.is_some_and(|n| n.ends_with("_test.go"));
json!({
"type": "request",
"command": "launch",
"arguments": {
"mode": if is_test { "test" } else { "debug" },
"program": dir.to_string_lossy(),
"cwd": dir.to_string_lossy(),
"stopOnEntry": false,
}
})
}
pub fn with_remote_output(mut request: Value) -> Value {
if request["command"] == "launch"
&& let Some(args) = request.get_mut("arguments").and_then(Value::as_object_mut)
{
args.entry("outputMode").or_insert_with(|| json!("remote"));
}
request
}
pub fn delve_test_request(dir: &Path, args: &[String]) -> Value {
json!({
"type": "request",
"command": "launch",
"arguments": {
"mode": "test",
"program": dir.to_string_lossy(),
"cwd": dir.to_string_lossy(),
"args": args,
"stopOnEntry": false,
}
})
}
pub fn lldb_launch_request(program: &Path, stop_on_entry: bool) -> Value {
json!({
"type": "request",
"command": "launch",
"arguments": {
"program": program.to_string_lossy(),
"stopOnEntry": stop_on_entry,
}
})
}
pub fn lldb_test_launch_request(program: &Path, args: &[String]) -> Value {
json!({
"type": "request",
"command": "launch",
"arguments": {
"program": program.to_string_lossy(),
"args": args,
"stopOnEntry": false,
}
})
}
pub fn pytest_debug_launch_request(python: &Path, cwd: &Path, name: &str) -> Value {
json!({
"type": "request",
"command": "launch",
"arguments": {
"request": "launch",
"module": "pytest",
"args": ["-v", "-k", name],
"python": [python.to_string_lossy()],
"cwd": cwd.to_string_lossy(),
"console": "internalConsole",
"stopOnEntry": false,
"justMyCode": true
}
})
}
pub fn launch_request(program: &Path, interpreter: &Path, stop_on_entry: bool) -> Value {
json!({
"type": "request",
"command": "launch",
"arguments": {
"request": "launch",
"program": program.to_string_lossy(),
"python": [interpreter.to_string_lossy()],
"console": "internalConsole",
"stopOnEntry": stop_on_entry,
"justMyCode": true
}
})
}
pub fn js_launch_request(program: &Path, cwd: &Path, stop_on_entry: bool) -> Value {
json!({
"type": "request",
"command": "launch",
"arguments": {
"type": "pwa-node",
"request": "launch",
"program": program.to_string_lossy(),
"cwd": cwd.to_string_lossy(),
"__workspaceFolder": cwd.to_string_lossy(),
"console": "internalConsole",
"sourceMaps": true,
"stopOnEntry": stop_on_entry
}
})
}
pub fn configuration_done_request() -> Value {
json!({ "type": "request", "command": "configurationDone", "arguments": {} })
}
pub(super) fn is_attach(request: &Value) -> bool {
request["command"] == "attach"
}
pub(super) fn disconnect_request(attached: bool) -> Value {
json!({
"type": "request",
"command": "disconnect",
"arguments": { "terminateDebuggee": !attached }
})
}