Repository navigation
Add Java main-method gutter debugging for JDTLS and Metals - #330
Conversation
|
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.
|
a1b3d9d to
b902a69
Compare
|
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'. |
|
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.
|
064ecfe to
b94b801
Compare
|
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'. |
b94b801 to
1d219a5
Compare
|
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'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
1d219a5 to
c10b9a7
Compare
| }, | ||
| "mainFile": { | ||
| "type": "string", | ||
| "description": "The absolute path to a Java source file, or $ZED_FILE. Resolves the main class and project from this file and builds before launch. Use mainClass and projectName to disambiguate multiple entries." |
There was a problem hiding this comment.
Cannot $ZED_FILE be rephrased into current focused file? Stating just $ZED_FILE might confuse the most.
There was a problem hiding this comment.
Updated the schema description to explain that $ZED_FILE refers to the currently focused Java source file, while keeping the variable spelling available for users writing a configuration.
| resolved_label: String, | ||
| debug_adapter_name: &str, | ||
| ) -> Option<zed::DebugScenario> { | ||
| if locator_name != "java" { |
There was a problem hiding this comment.
Could there be an instance where locator is different from java?
There was a problem hiding this comment.
There is only one registered locator in this extension, java, so the extra name check is redundant here. Removed the check and the helper's locator_name parameter; the required extension callback argument is now _locator_name.
| return Err(format!( | ||
| "Multiple Java main methods found in {main_file}; specify mainClass and projectName in .zed/debug.json" |
There was a problem hiding this comment.
Can we do something to decrease attrition here? Does the task provide a way to retrieve where the locator has been used to infer the correct main class?
There was a problem hiding this comment.
Yes, the runnable query already captures the class name. The built-in main task now carries it as ZED_JAVA_MAIN_CLASS=$ZED_CUSTOM_java_class_name, and the locator copies that hint into the JDTLS scenario's mainClass. It stays as a template until Zed substitutes the task variables before launch.
The JDTLS launch path then resolves candidates within mainFile, filters by that class, and retains the resolved fully qualified name and project. This selects the clicked class when one file has multiple main classes, without requiring .zed/debug.json. The file scopes the simple class name, so no package concatenation is necessary, including for the default package.
Added coverage for same-file selection, default-package classes, fully qualified name matching, and remaining project ambiguity. Custom tasks without a hint still use file discovery; ambiguous results still fail explicitly. The Metals mapping continues to use its existing file-discovery path. The new selection has automated coverage, but I have not repeated the interactive Zed run for this follow-up.
There was a problem hiding this comment.
It looks good, thanks
c10b9a7 to
6711cd9
Compare
|
@fwrq41251 I don't see the changes you talked about in the comments' followups. Remember to push the new commit to reflect what you described. |
|
The changes are in the current head
You may need to reload or use "View changes since last review" — the threads show the hunks from before the force-push. Sorry for the extra trip; I'll push follow-ups as separate commits from now on. |
|
@fwrq41251 let's avoid amending commits, it breaks the natural review flow and reviewing from the phone gets tougher 😅 |
- Carry the clicked class name from the gutter task as ZED_JAVA_MAIN_CLASS and filter JDTLS entries by it, accepting a simple or fully-qualified name. Keep project ambiguity an explicit error. - Drop the redundant locator-name parameter and check. - Clarify the mainFile/mainClass schema and README wording. - Cover same-file selection, non-matching suffixes and packages, and ambiguous projects with tests.
6711cd9 to
c86eafd
Compare
|
@tartarughina Thanks, understood. Split the branch into two commits: |
|
@fwrq41251 I've tested the extension after the latest changes and everything work as expected. Looking forward to the next PR to include tests as well. |
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) andMetalsdebug adapters, so either setup can debug a main method without.zed/debug.json.Refs #329. This covers main methods; test locators remain separate.
Changes
[debug_locators.java]and identify the built-injava-maintask withZED_JAVA_RUNNABLE=main. Runnable recognition is independent of the selected adapter.Java, generate a launch scenario containingmainFile: "$ZED_FILE"and a class hint fromZED_JAVA_MAIN_CLASS, supplied by the built-in task as$ZED_CUSTOM_java_class_name. Zed substitutes the captured class name before launch. At launch, resolve entries in that file throughvscode.java.resolveMainMethod, select the matching class, retain its fully qualified name and project identity, and callvscode.java.buildWorkspacebefore the existing classpath resolution and session startup. Only build success code1permits launch.vscode.java.buildWorkspaceup 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.Metals, generate the existing file-discovery launch configuration usingpath: "$ZED_FILE"andrunType: "runOrTestFile"; its adapter handles discovery and session preparation.mainFileto the Java configuration schema. Existing manual configurations withoutmainFileretain their launch behavior.For JDTLS, the built-in gutter action selects the clicked class even when the file contains multiple main classes. With
mainFile, the class hint can be simple or fully qualified; the resolved entry supplies the fully qualified class and project used for building and launching. Custom tasks without a class hint continue to use file discovery. Missing or still-ambiguous entries stop the launch rather than choosing an arbitrary entry. A manual configuration can combinemainFile,mainClass, andprojectNameto 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: 106 tests passed, including ten locator tests and twelve tests for file-based launch preparation. Coverage includes adapter selection, task filtering, environment forwarding and metadata removal, deferred class variables, same-file main-class selection with and without a package, exact fully qualified names, project ambiguity, file URI encoding, project identity, missing entries, build status codes, and LSP failures.cargo clippy -p zed_java --all-targets -- -D warningscargo fmt --all --check,git diff --check, and JSON schema syntax validation.wasm32-wasip2.The following validation was completed before the review follow-up:
cargo test -p java-lsp-proxy: 58 tests passed. 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 java-lsp-proxy --all-targets -- -D warningswasm32-wasip1andwasm32-wasip2..zed/debug.json, using a two-module Maven fixture withexample.Mainin both modules and an additional main class in the first module:2; fixing it allowed debugging again.The new same-file class-selection behavior has automated coverage; it has not been exercised in a new interactive Zed session. 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.