Skip to content

Forward device_id via toolArgs so Flutter run honors it#86

Open
FrantisekGazo wants to merge 1 commit intozed-extensions:mainfrom
FrantisekGazo:fix/device-id-via-toolargs
Open

Forward device_id via toolArgs so Flutter run honors it#86
FrantisekGazo wants to merge 1 commit intozed-extensions:mainfrom
FrantisekGazo:fix/device-id-via-toolargs

Conversation

@FrantisekGazo
Copy link
Copy Markdown

@FrantisekGazo FrantisekGazo commented May 7, 2026

Summary

Closes #85.

The device_id field in .zed/debug.json is currently a no-op for Flutter launches. The extension reads it and forwards it as deviceId in the DAP launch JSON, but Flutter's DAP (flutter_tools/lib/src/debug_adapters/flutter_adapter.dart) does not actually read that field — grep -r deviceId packages/flutter_tools/lib/src/debug_adapters/ returns a single hit and it's a comment. Only toolArgs is forwarded to flutter run --machine.

This PR injects ["-d", device_id] into toolArgs when the user sets device_id explicitly, so device selection actually works.

Changes

  • src/dart.rs: when device_id is explicitly present in the user config, append ["-d", <id>] to a toolArgs array in the launch JSON. If the user did not set device_id, leave toolArgs empty so Flutter's auto-pick stays in effect (preserves current behavior for users who don't specify a device).
  • The existing deviceId JSON field is left in place for forward-compat in case Flutter ever wires it up.
  • Bumped version to 0.3.7 in extension.toml, Cargo.toml, and Cargo.lock.

Net diff: ~12 lines.

Verification

DAP-level (hand-built launch requests piped to flutter debug_adapter, Flutter 3.41.6 stable):

Launch JSON Result
{"deviceId": "macos", ...} (current behavior) "More than one device connected", exits
{"toolArgs": ["-d", "macos"], ...} (this PR) macOS app launches successfully

End-to-end in Zed 1.1.6 (patched extension installed as a dev extension, Flutter 3.41.6, with an Android emulator + iPhone + macOS desktop + Chrome web all available):

  • device_id: "macos" → launches on macOS (previously hijacked to the running emulator)
  • device_id: "emulator-5554" → launches on the emulator
  • No device_id set → Flutter's auto-pick selects the emulator (current behavior unchanged)
  • CI build (cargo build --target wasm32-wasip1 --release)

Related

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
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

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'.

@FrantisekGazo
Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label May 7, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 7, 2026

The cla-bot has been summoned, and re-checked this pull request!

@FrantisekGazo FrantisekGazo marked this pull request as draft May 7, 2026 14:10
@FrantisekGazo FrantisekGazo marked this pull request as ready for review May 7, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

device_id in .zed/debug.json is silently ignored — Flutter device selection never works

1 participant