From 0f12a5298427e5a40d8571b599396f0eb2fd97b6 Mon Sep 17 00:00:00 2001 From: fwrq41251 <6220591+fwrq41251@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:16:26 +0900 Subject: [PATCH] Enable Metals for Java test gutter debugging --- README.md | 13 ++++++++----- src/debug_locator.rs | 7 +++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d3de48f..e02f3cc 100644 --- a/README.md +++ b/README.md @@ -227,8 +227,8 @@ describes its setup and restrictions. Test method and class tasks use the `ZED_JAVA_RUNNABLE=test-method` and `ZED_JAVA_RUNNABLE=test-class` markers. Their existing Run commands are preserved. -The locator creates a `testTarget` containing the source file, class, optional -outer class, and optional method. Discovery and compilation happen only when +The locator creates a `testTarget` containing the source file, package, class, +optional outer class, and optional method. Discovery and compilation happen only when you select Debug; creating the gutter action does not contact a language server. Project-wide test tasks are not converted to debug scenarios. @@ -243,11 +243,14 @@ TestNG uses its bundled runner. A local callback socket receives the test runner result protocol; this does not provide a test-results explorer. Build failures, missing targets, and ambiguous method names stop the launch. -Test gutter debugging is available with the `Java` adapter. All invocations of a -parameterized method are selected together. +With a Scala extension that supports Java `testTarget`, selecting the `Metals` +adapter discovers the test build target and starts a test class or method through +Metals. Framework and build-server support for selecting individual methods may +vary. All invocations of a parameterized method are selected together with JDTLS. Custom project tasks that replace the built-in Java tasks must also include the -appropriate marker. Select `Java` in `languages.Java.debuggers` for test debugging. +appropriate marker. Select the desired adapter in `languages.Java.debuggers` for +test debugging. ### Debugging with JDTLS diff --git a/src/debug_locator.rs b/src/debug_locator.rs index 96e98da..23dd74c 100644 --- a/src/debug_locator.rs +++ b/src/debug_locator.rs @@ -36,7 +36,7 @@ impl JavaRunnable { "path": "$ZED_FILE", "runType": "runOrTestFile", })), - (Self::TestMethod | Self::TestClass, "Java") => { + (Self::TestMethod | Self::TestClass, "Java" | "Metals") => { let mut target = json!({ "file": "$ZED_FILE", "className": "$ZED_CUSTOM_java_class_name", @@ -211,8 +211,8 @@ mod tests { let mut task = main_task(); task.env = vec![(RUNNABLE_ENV.into(), runnable.into())]; - { - let scenario = create_scenario(task.clone(), "Debug test".into(), "Java").unwrap(); + for adapter in ["Java", "Metals"] { + let scenario = create_scenario(task.clone(), "Debug test".into(), adapter).unwrap(); let config: Value = from_str(&scenario.config).unwrap(); assert_eq!(config["testTarget"]["file"], "$ZED_FILE"); assert_eq!( @@ -226,7 +226,6 @@ mod tests { runnable == "test-method" ); } - assert!(create_scenario(task, "Debug test".into(), "Metals").is_none()); } }