Skip to content

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

@FrantisekGazo

Description

@FrantisekGazo

Summary

The device_id field documented in the debug adapter schema is read from user config and forwarded to Flutter's DAP as deviceId, but Flutter's DAP never reads this field. As a result, flutter run is invoked without -d <id> and falls back to its auto-pick logic — so users either hit "More than one device connected" errors or silently launch on the wrong device.

Reproduction

.zed/debug.json:

{
  "label": "UI Demo: Debug on macOS",
  "adapter": "Dart",
  "type": "flutter",
  "request": "launch",
  "program": "lib/main.dart",
  "cwd": "$ZED_WORKTREE_ROOT/path/to/flutter-project",
  "device_id": "macos",
  "useFvm": true
}

With both macOS desktop and Chrome web available, launching this task fails with:

More than one device connected; please specify a device with the '-d <deviceId>' flag, or use '-d all' to act on all devices.

macOS (desktop) • macos  • darwin-arm64   • macOS 26.1 25B78 darwin-arm64
Chrome (web)    • chrome • web-javascript • Google Chrome 147.0.7727.138

Exited (1).

With an Android emulator additionally connected, the macOS task instead launches on the emulator (auto-pick of the only ephemeral device) — device_id: "macos" is still ignored.

Root cause (verified end-to-end)

  1. Extension side (src/dart.rs get_dap_binary) reads device_id and emits it as deviceId in the launch JSON sent to flutter debug_adapter. ✅
  2. Flutter side (flutter_tools/lib/src/debug_adapters/flutter_adapter.dart, launchImpl) builds the flutter run --machine ... argv from toolArgs and args.toolArgs (i.e. user-provided toolArgs). It never reads the deviceId field — grep -r deviceId packages/flutter_tools/lib/src/debug_adapters/ returns a single hit, and it's a comment.

Verified by sending hand-built DAP launch requests to flutter debug_adapter:

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

Tested on Flutter 3.41.6 stable, Zed 1.1.6, dart extension 0.3.6.

Proposed fix

In src/dart.rs get_dap_binary, translate device_id into toolArgs: ["-d", device_id] in the launch JSON. Two viable shapes:

  • Implicit: keep the device_id config field; in the extension, append ["-d", device_id] to a toolArgs array sent to the DAP.
  • Explicit: expose a toolArgs field in the schema (which Fix debug adapter config bugs and add missing config options #66 already proposes) and let users write toolArgs: ["-d", "macos"] themselves. Less convenient, but more flexible.

Ideally both — auto-translate device_id and support toolArgs for other flags (--flavor, --dart-define, etc.).

Related work

Either approach (or both combined) would close this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions