diff --git a/debug_adapter_schemas/Dart.json b/debug_adapter_schemas/Dart.json index c1cd44f..a2cd0e1 100644 --- a/debug_adapter_schemas/Dart.json +++ b/debug_adapter_schemas/Dart.json @@ -41,7 +41,7 @@ }, "useFvm": { "type": "boolean", - "description": "Weather to use fvm to run the Dart/Flutter program" + "description": "Whether to use fvm to run the Dart/Flutter program" }, "args": { "type": "array", @@ -51,6 +51,32 @@ }, "default": [] }, + "toolArgs": { + "type": "array", + "description": "Arguments passed to the Flutter/Dart tool (e.g. --flavor, -d chrome).", + "items": { + "type": "string" + }, + "default": [] + }, + "env": { + "type": "object", + "description": "Environment variables to set when launching the debug adapter.", + "additionalProperties": { + "type": "string" + } + }, + "flutterMode": { + "type": "string", + "enum": [ + "debug", + "profile", + "release", + "test" + ], + "description": "The Flutter mode to use.", + "default": "debug" + }, "device_id": { "type": "string", "examples": [ @@ -92,4 +118,4 @@ "adapter" ], "additionalProperties": false -} \ No newline at end of file +} diff --git a/languages/dart/tasks.json b/languages/dart/tasks.json index 472aa43..8234572 100644 --- a/languages/dart/tasks.json +++ b/languages/dart/tasks.json @@ -27,8 +27,8 @@ }, { "label": "fvm flutter run", - "command": "fvm flutter", - "args": ["run"], + "command": "fvm", + "args": ["flutter", "run"], "tags": ["flutter-main"] }, { @@ -39,8 +39,8 @@ }, { "label": "fvm flutter test $ZED_STEM", - "command": "fvm flutter", - "args": ["test", "$ZED_FILE"], + "command": "fvm", + "args": ["flutter", "test", "$ZED_FILE"], "tags": ["flutter-test-main"] }, { diff --git a/src/dart.rs b/src/dart.rs index 66e265c..15fd59f 100644 --- a/src/dart.rs +++ b/src/dart.rs @@ -7,6 +7,16 @@ use zed_extension_api::{ StartDebuggingRequestArguments, StartDebuggingRequestArgumentsRequest, Worktree, }; +fn tool_binary(debug_mode: &str) -> &'static str { + let (os, _) = current_platform(); + match (debug_mode, os) { + ("flutter", Os::Windows) => "flutter.bat", + ("flutter", _) => "flutter", + (_, Os::Windows) => "dart.bat", + (_, _) => "dart", + } +} + struct DartBinary { pub path: String, pub args: Option>, @@ -90,21 +100,10 @@ impl zed::Extension for DartExtension { let debug_mode = user_config .get("type") .and_then(|v| v.as_str()) - .filter(|s| !s.trim().is_empty()) // Filter out empty strings + .filter(|s| !s.trim().is_empty()) .ok_or_else(|| "type is required and cannot be empty or null".to_string())?; - let (os, _) = current_platform(); - let tool = if debug_mode == "flutter" { - match os { - Os::Windows => "flutter.bat", - _ => "flutter", - } - } else { - match os { - Os::Windows => "dart.bat", - _ => "dart", - } - }; + let tool = tool_binary(debug_mode); let (command, arguments) = if use_fvm { ( @@ -138,33 +137,73 @@ impl zed::Extension for DartExtension { let vm_service_uri = user_config.get("vmServiceUri").and_then(|v| v.as_str()); - let config_json = json!({ - "type": tool, + let stop_on_entry = user_config + .get("stopOnEntry") + .and_then(|v| v.as_bool()) + .unwrap_or(false); + + let flutter_mode = user_config + .get("flutterMode") + .and_then(|v| v.as_str()) + .unwrap_or("debug"); + + let tool_args = user_config + .get("toolArgs") + .and_then(|v| v.as_array()) + .map(|arr| { + arr.iter() + .filter_map(|v| v.as_str()) + .map(|s| s.to_string()) + .collect::>() + }) + .unwrap_or_default(); + + let env = user_config + .get("env") + .and_then(|v| v.as_object()) + .map(|obj| { + obj.iter() + .map(|(k, v)| (k.clone(), v.as_str().unwrap_or_default().to_string())) + .collect::>() + }) + .unwrap_or_default(); + + // Use debug_mode ("flutter"/"dart") rather than tool binary name so that + // the config is correct on all platforms (e.g. not "flutter.bat" on Windows). + let mut config_json = json!({ + "type": debug_mode, "request": request, - "vmServiceUri": vm_service_uri, "program": program, "cwd": cwd.clone().unwrap_or_default(), "args": args, - "flutterMode": "debug", + "flutterMode": flutter_mode, "deviceId": device_id, "platform": platform, - "stopOnEntry": false - }) - .to_string(); + "stopOnEntry": stop_on_entry, + "sendLogsToClient": true + }); + + if let Some(uri) = vm_service_uri { + config_json["vmServiceUri"] = json!(uri); + } + + if !tool_args.is_empty() { + config_json["toolArgs"] = json!(tool_args); + } let debug_adapter_binary = DebugAdapterBinary { command: Some(command), arguments, - envs: vec![], // Add any Dart-specific env vars if needed + envs: env, cwd, connection: None, request_args: StartDebuggingRequestArguments { - configuration: config_json, + configuration: config_json.to_string(), request: match request { "attach" => StartDebuggingRequestArgumentsRequest::Attach, _ => StartDebuggingRequestArgumentsRequest::Launch, }, - }, // request_args: StartDebuggingRequestArguments:, + }, }; Result::Ok(debug_adapter_binary) }