Forward device_id via toolArgs so Flutter run honors it#86
Forward device_id via toolArgs so Flutter run honors it#86FrantisekGazo wants to merge 6 commits into
Conversation
The top-level `deviceId` field in the DAP launch JSON is documented but not actually read by Flutter's DAP (only the comment at flutter_adapter.dart:425 mentions it). Only `toolArgs` are forwarded to `flutter run --machine`. Inject `["-d", device_id]` into `toolArgs` when the user sets `device_id` explicitly, so device selection works. Without this, `device_id: "macos"` (or any other id) is silently ignored and Flutter falls back to its auto-pick logic — yielding either "More than one device connected" errors or launches on the wrong device. Refs zed-extensions#85
|
We require contributors to sign our Contributor License Agreement, and we don't have @FrantisekGazo on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@MrSubidubi could you please review this PR? |
|
Hey, sorry for the delay! Could you please quickly merge main and update your changes to the older PR I just merged? I think there are some semantic conflicts and I'll hold off releasing a new version here until we resolved this here. Hope that works for you! |
|
sure. i merged the main now, but there we no conflicts |
|
I do think there are some, see line 203. I think we might need to update the logic here perhaps and/or change the schema? |
|
Note I mentioned
merge conflicts 🙂 |
|
Good catch — merging main left three semantic conflicts with #66:
Fixed in
Verified end-to-end: |
|
@MrSubidubi one more thing — the It's technically a breaking rename, but only of a field that never actually did anything. Are you OK with me including that here, or would you prefer to keep |
Summary
Closes #85.
The
device_idfield in.zed/debug.jsonis currently a no-op for Flutter launches. The extension reads it and forwards it asdeviceIdin the DAP launch JSON, but Flutter's DAP (flutter_tools/lib/src/debug_adapters/flutter_adapter.dart) does not read that field —grep -r deviceId packages/flutter_tools/lib/src/debug_adapters/returns a single hit and it's a comment. OnlytoolArgsis forwarded toflutter run --machine.This PR forwards
device_idas["-d", <id>]intoolArgsso device selection actually works, and defines how it interacts with the user-facingtoolArgsoption added in #66.Changes
src/dart.rs:device_idis set explicitly, append["-d", <id>]to the user'stoolArgs— but only if the user hasn't already passed a device flag (-d/--device-id) themselves. In that case the user'stoolArgstakes precedence.fluttermode only (dart runhas no-dflag).device_idis not set, nothing is injected — Flutter's auto-pick stays in effect (preserves current behavior for users who don't specify a device)."chrome"default for thedeviceIdJSON field. It was never read by Flutter's DAP, and now that device selection flows through-d, an unconditional default there would hijack Flutter's auto-pick.deviceIdis now emitted only when the user sets it, kept purely for forward-compat in case Flutter ever wires it up.debug_adapter_schemas/Dart.json: documenteddevice_idand its precedence relative totoolArgs.Precedence
device_idunsetdevice_id: "macos"flutter run -d macosdevice_idset +-d/--device-idalready intoolArgstoolArgswins, no injectiontype: "dart"-dinjection (dart has no device flag)Verification
DAP-level (hand-built launch requests piped to
flutter debug_adapter, Flutter 3.41.6 stable):{"deviceId": "macos", ...}(old behavior){"toolArgs": ["-d", "macos"], ...}(this PR)End-to-end in Zed (patched extension installed as a dev extension, Flutter 3.41.6, with an Android emulator + macOS desktop + Chrome web all available):
device_id: "macos"→ launches on macOS (previously hijacked to the running emulator)device_idset → Flutter's auto-pick selects the emulator (current behavior unchanged)device_id+ explicit-dintoolArgs→ user'stoolArgswinsRelated
toolArgsconfig field. This PR builds on it:device_idis merged intotoolArgs, with the user's explicit device flag taking precedence.-d <id>viatoolArgsmechanism as part of its hot-reload feature.