From 7d3d16660b46a6cf7b8d70804a6fb37ea3f1201c Mon Sep 17 00:00:00 2001 From: "Paulo J. Cagol" Date: Wed, 18 Mar 2026 17:25:47 -0300 Subject: [PATCH] Add hot reload and hot restart custom actions 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 ` 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) --- Cargo.toml | 2 +- src/dart.rs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 598784b..3ad65fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ path = "src/dart.rs" crate-type = ["cdylib"] [dependencies] -zed_extension_api = "0.7.0" +zed_extension_api = "0.8.0" diff --git a/src/dart.rs b/src/dart.rs index 66e265c..edff770 100644 --- a/src/dart.rs +++ b/src/dart.rs @@ -3,7 +3,8 @@ use zed::settings::LspSettings; use zed::{CodeLabel, CodeLabelSpan}; use zed_extension_api::serde_json::json; use zed_extension_api::{ - self as zed, current_platform, serde_json, DebugAdapterBinary, DebugTaskDefinition, Os, Result, + self as zed, current_platform, serde_json, DapCustomAction, DapCustomActionIcon, + DapCustomActionTrigger, DebugAdapterBinary, DebugTaskDefinition, Os, Result, StartDebuggingRequestArguments, StartDebuggingRequestArgumentsRequest, Worktree, }; @@ -138,6 +139,12 @@ impl zed::Extension for DartExtension { let vm_service_uri = user_config.get("vmServiceUri").and_then(|v| v.as_str()); + let tool_args = if debug_mode == "flutter" { + vec!["-d".to_string(), device_id.to_string()] + } else { + vec![] + }; + let config_json = json!({ "type": tool, "request": request, @@ -145,6 +152,7 @@ impl zed::Extension for DartExtension { "program": program, "cwd": cwd.clone().unwrap_or_default(), "args": args, + "toolArgs": tool_args, "flutterMode": "debug", "deviceId": device_id, "platform": platform, @@ -217,6 +225,29 @@ impl zed::Extension for DartExtension { }))) } + fn get_dap_custom_actions(&self, adapter_name: String) -> Vec { + if adapter_name != "Flutter" && adapter_name != "Dart" { + return Vec::new(); + } + + vec![ + DapCustomAction { + label: "Hot Reload".to_string(), + command: "hotReload".to_string(), + arguments: "{}".to_string(), + trigger: DapCustomActionTrigger::Both, + icon: DapCustomActionIcon::Flame, + }, + DapCustomAction { + label: "Hot Restart".to_string(), + command: "hotRestart".to_string(), + arguments: "{}".to_string(), + trigger: DapCustomActionTrigger::Toolbar, + icon: DapCustomActionIcon::RotateCw, + }, + ] + } + fn label_for_completion( &self, _language_server_id: &zed::LanguageServerId,