Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ Add the following to your `settings.json` to enable features like organizing imp
}
```

### Debugging tests (`.zed/debug.json`)

Set `"testMode": true` in a debug configuration to run the target file as a test
suite. The extension spawns the debug adapter with `--test`, so the program runs
via `flutter test` / `dart test` (headless) instead of `flutter run` / `dart run`.
Breakpoints, stepping, and variable inspection work as usual.

```json
{
"label": "Debug current test file",
"adapter": "Dart",
"type": "flutter",
"request": "launch",
"program": "$ZED_FILE",
"cwd": "$ZED_DIRNAME",
"testMode": true,
"useFvm": true
}
```

Zed task variables such as `$ZED_FILE` and `$ZED_DIRNAME` work in `.zed/debug.json`.
Use `"toolArgs"` to narrow the run, e.g. `"toolArgs": ["--plain-name", "<test name>"]`.
For a pure-Dart package, set `"type": "dart"` instead (`dart debug_adapter --test`).

## Documentation

See:
Expand Down
8 changes: 6 additions & 2 deletions debug_adapter_schemas/Dart.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
"type": "boolean",
"description": "Whether to use fvm to run the Dart/Flutter program"
},
"testMode": {
"type": "boolean",
"description": "Run the program as a test suite (spawns the debug adapter with --test, i.e. flutter test / dart test instead of flutter run / dart run).",
"default": false
},
"args": {
"type": "array",
"description": "Arguments passed to the Dart program.",
Expand Down Expand Up @@ -71,8 +76,7 @@
"enum": [
"debug",
"profile",
"release",
"test"
"release"
],
"description": "The Flutter mode to use.",
"default": "debug"
Expand Down
22 changes: 16 additions & 6 deletions src/dart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ impl zed::Extension for DartExtension {
.and_then(|v| v.as_bool())
.unwrap_or(false);

let test_mode = user_config
.get("testMode")
.and_then(|v| v.as_bool())
.unwrap_or(false);

// Get debug_mode from user config (flutter or dart)
let debug_mode = user_config
.get("type")
Expand All @@ -106,12 +111,17 @@ impl zed::Extension for DartExtension {
let tool = tool_binary(debug_mode);

let (command, arguments) = if use_fvm {
(
"fvm".to_string(),
vec![tool.to_string(), "debug_adapter".to_string()],
)
let mut args = vec![tool.to_string(), "debug_adapter".to_string()];
if test_mode {
args.push("--test".to_string());
}
("fvm".to_string(), args)
} else {
(tool.to_string(), vec!["debug_adapter".to_string()])
let mut args = vec!["debug_adapter".to_string()];
if test_mode {
args.push("--test".to_string());
}
(tool.to_string(), args)
};

let device_id = user_config.get("deviceId").and_then(|v| v.as_str());
Expand Down Expand Up @@ -160,7 +170,7 @@ impl zed::Extension for DartExtension {
// which is the only path the DAP actually honors. Only inject when the
// user set `deviceId` explicitly and did not already pass a device via
// `toolArgs` — otherwise leave selection to Flutter's auto-pick.
if debug_mode == "flutter" {
if debug_mode == "flutter" && !test_mode {
if let Some(id) = device_id {
let has_device_arg = tool_args
.iter()
Expand Down