diff --git a/src/odin.rs b/src/odin.rs index 6fb0426..025d5f3 100644 --- a/src/odin.rs +++ b/src/odin.rs @@ -429,9 +429,11 @@ impl zed::Extension for OdinExtension { resolved_label: String, debug_adapter_name: String, ) -> Option { - // Only handle Odin run tasks - if build_task.command != "odin" || build_task.args.is_empty() || build_task.args[0] != "run" - { + let is_run = build_task.command == "odin" && build_task.args.first() == Some(&"run".into()); + let is_test = + build_task.command == "odin" && build_task.args.first() == Some(&"test".into()); + + if !is_run && !is_test { return None; } @@ -449,9 +451,17 @@ impl zed::Extension for OdinExtension { build_args.push("-debug".into()); } + if is_test { + build_args.push("-build-mode:test".into()) + } + // Create the build task template let build_template = BuildTaskTemplate { - label: "odin debug build".into(), + label: if is_test { + "odin debug test".into() + } else { + "odin debug build".into() + }, command: build_task.command.clone(), args: build_args, env: build_task.env.clone(), @@ -461,12 +471,20 @@ impl zed::Extension for OdinExtension { // Config is Null - the actual launch config comes from run_dap_locator let config = serde_json::to_string(&serde_json::Value::Null).ok()?; - // Remove 'run: ' from the task label, since 'debug: ' will be prepended by default - let label = resolved_label - .clone() - .strip_prefix("run: ") - .unwrap_or(&resolved_label) - .to_string(); + // Update the task labels. The resulting label will be displayed as-is in + // the F4 Debug menu and will have "Debug: " prepended to the label when + // shown in the test gutter. + let label = if is_run { + resolved_label + .strip_prefix("run: ") + .unwrap_or(&resolved_label) + .to_string() + } else { + resolved_label + .strip_prefix("test: ") + .map(|suffix| format!("test {}", suffix)) + .unwrap_or_else(|| resolved_label.clone()) + }; Some(DebugScenario { adapter: debug_adapter_name, @@ -487,12 +505,12 @@ impl zed::Extension for OdinExtension { _locator_name: String, build_task: TaskTemplate, ) -> Result { - // Only handle Odin build tasks + // Only handle Odin build and test tasks if build_task.command != "odin" || build_task.args.is_empty() - || build_task.args[0] != "build" + || !(build_task.args[0] == "build" || build_task.args[0] == "test") { - return Err("Not an Odin build task".to_string()); + return Err("Not an Odin build or test task".to_string()); } // Extract the binary name from the -out: flag