diff --git a/debug_adapter_schemas/Dart.json b/debug_adapter_schemas/Dart.json index a2cd0e1..1a70fc5 100644 --- a/debug_adapter_schemas/Dart.json +++ b/debug_adapter_schemas/Dart.json @@ -77,8 +77,9 @@ "description": "The Flutter mode to use.", "default": "debug" }, - "device_id": { + "deviceId": { "type": "string", + "description": "The device to launch on, passed to the Flutter tool as `-d `. Ignored if toolArgs already contains -d/--device-id. If unset, Flutter auto-picks a device.", "examples": [ "chrome", "edge", diff --git a/src/dart.rs b/src/dart.rs index 15fd59f..2dd6c1e 100644 --- a/src/dart.rs +++ b/src/dart.rs @@ -114,10 +114,7 @@ impl zed::Extension for DartExtension { (tool.to_string(), vec!["debug_adapter".to_string()]) }; - let device_id = user_config - .get("device_id") - .and_then(|v| v.as_str()) - .unwrap_or("chrome"); + let device_id = user_config.get("deviceId").and_then(|v| v.as_str()); let platform = user_config .get("platform") @@ -147,7 +144,7 @@ impl zed::Extension for DartExtension { .and_then(|v| v.as_str()) .unwrap_or("debug"); - let tool_args = user_config + let mut tool_args = user_config .get("toolArgs") .and_then(|v| v.as_array()) .map(|arr| { @@ -158,6 +155,23 @@ impl zed::Extension for DartExtension { }) .unwrap_or_default(); + // Flutter's DAP does not read the top-level `deviceId` field, so the + // device id must be forwarded via `toolArgs` (`flutter run -d `), + // which is the only path the DAP actually honors. Only inject when the + // user set `deviceId` explicitly and did not already pass a device via + // `toolArgs` — otherwise leave selection to Flutter's auto-pick. + if debug_mode == "flutter" { + if let Some(id) = device_id { + let has_device_arg = tool_args + .iter() + .any(|arg| arg == "-d" || arg.starts_with("--device-id")); + if !has_device_arg { + tool_args.push("-d".to_string()); + tool_args.push(id.to_string()); + } + } + } + let env = user_config .get("env") .and_then(|v| v.as_object()) @@ -177,7 +191,6 @@ impl zed::Extension for DartExtension { "cwd": cwd.clone().unwrap_or_default(), "args": args, "flutterMode": flutter_mode, - "deviceId": device_id, "platform": platform, "stopOnEntry": stop_on_entry, "sendLogsToClient": true @@ -187,6 +200,12 @@ impl zed::Extension for DartExtension { config_json["vmServiceUri"] = json!(uri); } + // Kept for forward-compat in case Flutter's DAP ever reads it; only + // emitted when the user set a device explicitly. + if let Some(id) = device_id { + config_json["deviceId"] = json!(id); + } + if !tool_args.is_empty() { config_json["toolArgs"] = json!(tool_args); }