Skip to content

Add hot reload and hot restart custom actions#72

Draft
paulocagol wants to merge 1 commit into
zed-extensions:mainfrom
paulocagol:hot-reload-custom-actions
Draft

Add hot reload and hot restart custom actions#72
paulocagol wants to merge 1 commit into
zed-extensions:mainfrom
paulocagol:hot-reload-custom-actions

Conversation

@paulocagol

Copy link
Copy Markdown

Summary

  • Add hot reload and hot restart buttons to the debugger toolbar when debugging
    Flutter/Dart applications
  • Hot reload triggers automatically on file save (trigger: Both)
  • Hot restart is toolbar-only (trigger: Toolbar)
  • Fix device selection by passing -d <device_id> via toolArgs

Depends on: zed-industries/zed#51873 (custom debug actions Extension API).
Both PRs are intended to be reviewed and merged together.

Test plan

  • Start a Flutter debug session — "Hot Reload" (🔥) and "Hot Restart" (🔄)
    buttons appear in toolbar
  • Click Hot Reload button — app reloads preserving state
  • Click Hot Restart button — app restarts from scratch
  • Save a .dart file — hot reload triggers automatically
  • Verify device_id is respected (e.g., device_id: "macos" launches on macOS)

Release Notes:

  • Added Flutter hot reload and hot restart support to the Dart debug extension

Implement `get_dap_custom_actions` to expose Flutter hot reload and hot
restart as custom debug actions. Hot reload triggers both on toolbar click
and on file save; hot restart is toolbar-only.

Also fix device selection by passing `-d <device_id>` via `toolArgs` in
the launch configuration.

Depends on zed-industries/zed#51873 (custom debug actions Extension API).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cla-bot

cla-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @paulocagol 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'.

@paulocagol

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot

cla-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @paulocagol 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

cla-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

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

@paulocagol

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Mar 18, 2026
@cla-bot

cla-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

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

rwrz added a commit to rwrz/zed-flutter that referenced this pull request May 4, 2026
Three new tasks reachable from the pubspec gutter button (default
device / macOS / Chrome) plus a documented keymap snippet that binds
cmd-r, cmd-shift-r, cmd-q to terminal::SendText for hot reload, hot
restart, and quit while the terminal pane is focused.

This is a workaround until zed#51873 + zed-extensions/dart#72 land and
expose the DAP-based hot reload as a proper toolbar button. CLAUDE.md
documents the rationale.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MrSubidubi
MrSubidubi marked this pull request as draft May 27, 2026 10:59
MrSubidubi pushed a commit that referenced this pull request Jul 20, 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
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 forwards `device_id` as `["-d", <id>]` in `toolArgs` so device
selection actually works, and defines how it interacts with the
user-facing `toolArgs` option added in #66.

## Changes

- `src/dart.rs`:
- When `device_id` is set explicitly, append `["-d", <id>]` to the
user's `toolArgs` — but only if the user hasn't already passed a device
flag (`-d` / `--device-id`) themselves. In that case the user's
`toolArgs` takes precedence.
- The injection is gated to `flutter` mode only (`dart run` has no `-d`
flag).
- If `device_id` is not set, nothing is injected — Flutter's auto-pick
stays in effect (preserves current behavior for users who don't specify
a device).
- Removed the phantom `"chrome"` default for the `deviceId` JSON 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. `deviceId` is 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`: documented `device_id` and its
precedence relative to `toolArgs`.

## Precedence

| User config | Result |
|---|---|
| `device_id` unset | Flutter auto-picks a device (unchanged) |
| `device_id: "macos"` | `flutter run -d macos` |
| `device_id` set + `-d`/`--device-id` already in `toolArgs` | user's
`toolArgs` wins, no injection |
| `type: "dart"` | no `-d` injection (dart has no device flag) |

## Verification

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

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

**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):

- [x] `device_id: "macos"` → launches on macOS (previously hijacked to
the running emulator)
- [x] No `device_id` set → Flutter's auto-pick selects the emulator
(current behavior unchanged)
- [x] `device_id` + explicit `-d` in `toolArgs` → user's `toolArgs` wins

## Related

- #66 added the user-facing `toolArgs` config field. This PR builds on
it: `device_id` is merged into `toolArgs`, with the user's explicit
device flag taking precedence.
- #72 includes the same `-d <id>` via `toolArgs` mechanism as part of
its hot-reload feature.
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.

1 participant