Skip to content

Add Java main-method gutter debugging for JDTLS and Metals - #330

Open
fwrq41251 wants to merge 1 commit into
zed-extensions:mainfrom
fwrq41251:feat/metals-main-debug-locator
Open

fwrq41251 wants to merge 1 commit into
zed-extensions:mainfrom
fwrq41251:feat/metals-main-debug-locator

Conversation

@fwrq41251

@fwrq41251 fwrq41251 commented Nov 16, 2026 •

Copy link
Copy Markdown

Java main-method gutter actions currently expose Run without a Debug counterpart. Add a shared Java task locator with configuration mappings for the Java (JDTLS) and Metals debug adapters, so either setup can debug a main method without .zed/debug.json.

Refs #329. This covers main methods; test locators remain separate.

Changes

  • Register [debug_locators.java] and identify the built-in java-main task with ZED_JAVA_RUNNABLE=main. Runnable recognition is independent of the selected adapter.
  • For Java, generate a launch scenario containing mainFile: "$ZED_FILE". At launch, resolve the file through vscode.java.resolveMainMethod, retain its project identity, and call vscode.java.buildWorkspace before the existing classpath resolution and session startup. Only build success code 1 permits launch.
  • Allow vscode.java.buildWorkspace up to five minutes through the native LSP proxy while retaining the five-second timeout for other requests. Timeout errors report the actual duration, and timed-out requests are still cancelled.
  • For Metals, generate the existing file-discovery launch configuration using path: "$ZED_FILE" and runType: "runOrTestFile"; its adapter handles discovery and session preparation.
  • Keep gutter discovery free of LSP requests, session startup, and shell-task execution. Forward task environment overrides without the runnable marker. Unmarked tasks, test tasks, and unsupported adapters produce no scenario.
  • Document both setups and custom-task opt-in. Add mainFile to the Java configuration schema. Existing manual configurations without mainFile retain their launch behavior.

JDTLS file resolution fails explicitly when no matching main method exists or the file contains multiple matching main classes. A manual configuration can combine mainFile, mainClass, and projectName to disambiguate. The resolved project prevents same-named classes in different modules from being selected by a workspace-wide class-name lookup.

Validation

  • cargo test -p zed_java: 102 tests passed, including nine locator tests and nine tests for file-based launch preparation. Coverage includes adapter selection, task filtering, environment forwarding, file URI encoding, project identity, ambiguous/missing entries, build status codes, and LSP failures.
  • cargo test -p java-lsp-proxy: 58 tests passed. New coverage exercises the real HTTP handler with a build completing after six seconds, verifies ordinary requests still time out and send cancellation after five seconds, and checks that only the matching execute-command request gets the longer timeout.
  • cargo clippy -p zed_java --all-targets -- -D warnings
  • cargo clippy -p java-lsp-proxy --all-targets -- -D warnings
  • cargo fmt --all --check, git diff --check, and JSON schema syntax validation.
  • Release builds for wasm32-wasip1 and wasm32-wasip2.
  • Interactive verification in Zed 1.28.1 without .zed/debug.json, using a two-module Maven fixture with example.Main in both modules and an additional main class in the first module:
    • JDTLS 1.63.0 with Java Debug 0.53.2: gutter Debug actions launched both modules and stopped at each module's correct source breakpoint, with distinct local variable values and output.
    • After changing the second module's source without manually compiling, JDTLS debugging showed the updated value at the breakpoint and in output.
    • Introducing a compilation error stopped the JDTLS launch with build status 2; fixing it allowed debugging again.
    • Metals regression: with JDTLS disabled, the gutter action launched the second module, stopped at the correct breakpoint, and showed the updated value.

Metals verification used the existing Java-enabled Scala extension 0.2.5 installation and local Metals snapshot/proxy setup. This PR does not add Java registration to metals-zed or change its proxy. Gradle and other Metals/build-server combinations were not exercised interactively.

@cla-bot

cla-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: zhou.cong 周 聰-SaaS.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@fwrq41251
fwrq41251 force-pushed the feat/metals-main-debug-locator branch from a1b3d9d to b902a69 Compare November 16, 2026 00:20
@cla-bot

cla-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @fwrq41251 on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@fwrq41251 fwrq41251 changed the title Add Metals gutter debugging for Java main methods Add Java main-method debug locator with Metals support Nov 16, 2026
@cla-bot

cla-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: zhou.cong 周 聰-SaaS.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@fwrq41251
fwrq41251 force-pushed the feat/metals-main-debug-locator branch from 064ecfe to b94b801 Compare November 16, 2026 00:34
@cla-bot

cla-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @fwrq41251 on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@fwrq41251
fwrq41251 force-pushed the feat/metals-main-debug-locator branch from b94b801 to 1d219a5 Compare November 16, 2026 01:07
@fwrq41251 fwrq41251 changed the title Add Java main-method debug locator with Metals support Add Java main-method gutter debugging for JDTLS and Metals Nov 16, 2026
@cla-bot

cla-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @fwrq41251 on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@fwrq41251

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Nov 16, 2026
@cla-bot

cla-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@fwrq41251
fwrq41251 force-pushed the feat/metals-main-debug-locator branch from 1d219a5 to c10b9a7 Compare November 16, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant