Skip to content

Add debug locators so gutter actions offer Debug: ... for Java tests and main methods #329

Open

Description

@fwrq41251

What happened?

For Java, the gutter only offers run actions (Run Foo, Test class Foo, Foo.bar). There is no Debug: ... entry, unlike Rust/Go/Python/JS/TS where the gutter arrow shows both a run action and Debug: ... (see zed-industries/zed#60034 for a Go/Delve example).

Cause, from Zed's source:

  • crates/editor/src/code_actions.rs::debug_scenarios builds DebugScenarios by calling DapStore::debug_scenario_for_build_task for each resolved task.
  • crates/project/src/debugger/dap_store.rs walks DapRegistry::global(cx).locators() and yields None when no locator accepts the task.
  • crates/project/src/debugger/locators.rs only ships cargo, go, node, python.
  • This extension declares [debug_adapters.Java] but no [debug_locators.*], and src/java.rs only implements get_dap_binary / dap_request_kind.

So java-main, java-test-method, java-test-method-nested, java-test-class and java-test-class-nested tasks never get a debug counterpart, and the gutter shows run only.

What did you expect to happen?

Clicking the gutter arrow next to a @Test method, a test class, or a main method should offer both the existing run action and Debug: <label>, like IntelliJ.

Right now the only way to debug is a hand-written .zed/debug.json plus F4, and those scenarios never show up in the gutter.

Scope

Tests are the important half here, so a locator should cover:

  • java-main
  • java-test-method / java-test-method-nested
  • java-test-class / java-test-class-nested

(java-test-all — "Run tests" for a whole file/module — I'd leave out of a first PR.)

Suggested implementation

Declare [debug_locators.java] and implement dap_locator_create_scenario. No build phase is needed: the launch config is fully derivable from the task template, so the returned DebugScenario can omit build. dap_request_kind already maps request: "launch" correctly, so it needs no change.

Note that the table name must be snake_case ([debug_locators.java]); a kebab-case [debug-locators.java] silently fails to register — see zed-industries/zed#33040.

Classpath and main-class resolution already exist in src/debugger.rs::inject_config: it turns classPaths: ["$Test"] into a vscode.java.resolveClasspath call with test scope, and resolves the main class via vscode.java.resolveMainClass. So the plumbing for test scope is already there.

For main methods:

{ "request": "launch", "mainClass": "<package>.<Class>", "classPaths": ["$Auto"], "cwd": "$ZED_WORKTREE_ROOT" }

For tests, the missing piece is an entry point. debug_adapter_schemas/Java.json only exposes mainClass + args, and JUnit has no main, so the JVM has to be started with a test runner as mainClass. Two options:

  1. Ship a runner jar (what VS Code does): download com.microsoft.java.test.runner (from microsoft/vscode-java-test) the same way this extension already downloads the java-debug plugin, append it to classPaths, and use com.microsoft.java.test.runner.Launcher with -testName <Class#method> -classNames <Class>. Works for JUnit 4/5/TestNG without requiring the project to declare extra dependencies.
  2. Use junit-platform-console-standalone: mainClass: "org.junit.platform.console.ConsoleLauncher", args --select-class=<fqcn> or --select-method=<fqcn>#<method>, with the standalone jar appended to classPaths. Simpler, but JUnit 5 only, and still needs a bundled jar.

Option 1 matches VS Code and covers @ParameterizedTest and nested classes through the existing java_outer_class_name capture (Outer$Inner). Which would you prefer? I'm happy to implement either, and to split it into "main methods first, tests next" if you'd rather review it in two PRs.

Related

Environment

  • Zed: v1.27.0
  • Java extension: v6.8.30
  • OS: macOS 27.0.1 (aarch64)
  • JDK 21, Maven project (JUnit 5)

Activity

  1. tartarughina commented on Nov 11, 2026

    @tartarughina
    Collaborator

    @fwrq41251 thanks for sharing the findings above. I've missed that extensions were able to provide such option.

    About the implementation details:

    • let's proceed with the two PRs approach you suggested
    • for the tests I'm happy to go with option 1, especially as that's the same approach adopted by VS Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions