Skip to content

Commit 0e5cac6

Browse files
authored
Simplify configuration and docs (#115)
Closes #99 - add top-level configuration values for lombok_support and java_home - change lombok_support default to `true` - overhaul the `README`
1 parent 1991fc1 commit 0e5cac6

File tree

2 files changed

+141
-104
lines changed

2 files changed

+141
-104
lines changed

README.md

Lines changed: 126 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,139 @@
1-
# Zed Java
1+
# Java Extension for Zed
22

3-
This extension adds support for the Java language.
3+
This extension adds support for the Java language to [Zed](https://zed.dev). It is using the [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) (JDTLS for short) to provide completions, code-actions and diagnostics.
44

5-
## Configuration Options
5+
## Quick Start
66

7-
If [Lombok] support is enabled via [JDTLS] configuration option
8-
(`settings.java.jdt.ls.lombokSupport.enabled`), this
9-
extension will download and add [Lombok] as a javaagent to the JVM arguments for
10-
[JDTLS].
7+
Install the extension via Zeds extension manager. It should work out of the box for most people. However, there are some things to know:
118

12-
There are also many more options you can pass directly to the language server,
13-
for example:
9+
- It is generally recommended to open projects with the Zed-project root at the Java project root folder (where you would commonly have your `pom.xml` or `build.gradle` file).
10+
11+
- By default the extension will download and run the latest official version of JDTLS for you, but this requires Java version 21 to be available on your system via either the `$JAVA_HOME` environment variable or as a `java(.exe)` executable on your `$PATH`. If your project requires a lower Java version in the environment, you can specify a different JDK to use for running JDTLS via the `java_home` configuration option.
12+
13+
- You can provide a **custom launch script for JDTLS**, by adding an executable named `jdtls` (or `jdtls.bat` on Windows) to your `$PATH` environment variable. If this is present, the extension will skip downloading and launching a managed instance and use the one from the environment.
14+
15+
- To support [Lombok](https://projectlombok.org/), the lombok-jar must be downloaded and registered as a Java-Agent when launching JDTLS. By default the extension automatically takes care of that, but in case you don't want that you can set the `lombok_support` configuration-option to `false`.
16+
17+
Here is a common `settings.json` including the above mentioned configurations:
18+
19+
```jsonc
20+
"lsp": {
21+
"jdtls": {
22+
"settings": {
23+
"java_home": "/path/to/your/JDK21+",
24+
"lombok_support": true,
25+
}
26+
}
27+
}
28+
```
29+
30+
## Debugger
31+
32+
Debug support is enabled via our [Fork of Java Debug](https://github.com/zed-industries/java-debug), which the extension will automatically download and start for you. Please refer to the [Zed Documentation](https://zed.dev/docs/debugger#getting-started) for general information about how debugging works in Zed.
33+
34+
To get started with Java, click the `edit debug.json` button in the Debug menu, and replace the contents of the file with the following:
35+
```jsonc
36+
[
37+
{
38+
"adapter": "Java",
39+
"request": "launch",
40+
"label": "Launch Debugger",
41+
// if your project has multiple entry points, specify the one to use:
42+
// "mainClass": "com.myorganization.myproject.MyMainClass",
43+
//
44+
// this effectively sets a breakpoint at your program entry:
45+
"stopOnEntry": true,
46+
// the working directory for the debug process
47+
"cwd": "$ZED_WORKTREE_ROOT"
48+
}
49+
]
50+
```
51+
52+
You should then be able to start a new Debug Session with the "Launch Debugger" scenario from the debug menu.
53+
54+
## Launch Scripts (aka Tasks) in Windows
55+
56+
This extension provides tasks for running your application and tests from within Zed via little play buttons next to tests/entry points. However, due to current limitiations of Zed's extension interface, we can not provide scripts that will work across Maven and Gradle on both Windows and Unix-compatible systems, so out of the box the launch scripts only work on Mac and Linux.
57+
58+
There is a fairly straightforward fix that you can apply to make it work on Windows by supplying your own task scripts. Please see [this Issue](https://github.com/zed-extensions/java/issues/94) for information on how to do that and read the [Tasks section in Zeds documentation](https://zed.dev/docs/tasks) for more information.
59+
60+
## Advanced Configuration/JDTLS initialization Options
61+
JDTLS provides many configuration options that can be passed via the `initialize` LSP-request. The extension will pass the JSON-object from `lsp.jdtls.settings.initialization_options` in your settings on to JDTLS. Please refer to the [JDTLS Configuration Wiki Page](https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request) for the available options and values. Below is an example `settings.json` that would pass on the example configuration from the above wiki page to JDTLS:
1462

1563
```jsonc
1664
{
1765
"lsp": {
1866
"jdtls": {
19-
"initialization_options": {
20-
"bundles": [],
21-
"workspaceFolders": ["file:///home/snjeza/Project"],
22-
},
2367
"settings": {
24-
"java": {
25-
"home": "/usr/local/jdk-9.0.1",
26-
"errors": {
27-
"incompleteClasspath": {
28-
"severity": "warning",
29-
},
30-
},
31-
"configuration": {
32-
"updateBuildConfiguration": "interactive",
33-
"maven": {
34-
"userSettings": null,
35-
},
36-
},
37-
"trace": {
38-
"server": "verbose",
39-
},
40-
"import": {
41-
"gradle": {
42-
"enabled": true,
43-
},
44-
"maven": {
45-
"enabled": true,
46-
},
47-
"exclusions": [
48-
"**/node_modules/**",
49-
"**/.metadata/**",
50-
"**/archetype-resources/**",
51-
"**/META-INF/maven/**",
52-
"/**/test/**",
53-
],
54-
},
55-
"jdt": {
56-
"ls": {
57-
"lombokSupport": {
58-
"enabled": false, // Set this to true to enable lombok support
68+
// this will be sent to JDTLS as initializationOptions:
69+
"initialization_options": {
70+
"bundles": [],
71+
// use this if your zed project root folder is not the same as the java project root:
72+
"workspaceFolders": ["file:///home/snjeza/Project"],
73+
"settings": {
74+
"java": {
75+
"home": "/usr/local/jdk-9.0.1",
76+
"errors": {
77+
"incompleteClasspath": {
78+
"severity": "warning"
79+
}
80+
},
81+
"configuration": {
82+
"updateBuildConfiguration": "interactive",
83+
"maven": {
84+
"userSettings": null
85+
}
86+
},
87+
"import": {
88+
"gradle": {
89+
"enabled": true
90+
},
91+
"maven": {
92+
"enabled": true
93+
},
94+
"exclusions": [
95+
"**/node_modules/**",
96+
"**/.metadata/**",
97+
"**/archetype-resources/**",
98+
"**/META-INF/maven/**",
99+
"/**/test/**"
100+
]
101+
},
102+
"referencesCodeLens": {
103+
"enabled": false
104+
},
105+
"signatureHelp": {
106+
"enabled": false
59107
},
60-
},
61-
},
62-
"referencesCodeLens": {
63-
"enabled": false,
64-
},
65-
"signatureHelp": {
66-
"enabled": false,
67-
},
68-
"implementationsCodeLens": {
69-
"enabled": false,
70-
},
71-
"format": {
72-
"enabled": true,
73-
},
74-
"saveActions": {
75-
"organizeImports": false,
76-
},
77-
"contentProvider": {
78-
"preferred": null,
79-
},
80-
"autobuild": {
81-
"enabled": false,
82-
},
83-
"completion": {
84-
"favoriteStaticMembers": [
85-
"org.junit.Assert.*",
86-
"org.junit.Assume.*",
87-
"org.junit.jupiter.api.Assertions.*",
88-
"org.junit.jupiter.api.Assumptions.*",
89-
"org.junit.jupiter.api.DynamicContainer.*",
90-
"org.junit.jupiter.api.DynamicTest.*",
91-
],
92-
"importOrder": ["java", "javax", "com", "org"],
93-
},
94-
},
95-
},
96-
},
97-
},
108+
"implementationCodeLens": "all",
109+
"format": {
110+
"enabled": true
111+
},
112+
"saveActions": {
113+
"organizeImports": false
114+
},
115+
"contentProvider": {
116+
"preferred": null
117+
},
118+
"autobuild": {
119+
"enabled": false
120+
},
121+
"completion": {
122+
"favoriteStaticMembers": [
123+
"org.junit.Assert.*",
124+
"org.junit.Assume.*",
125+
"org.junit.jupiter.api.Assertions.*",
126+
"org.junit.jupiter.api.Assumptions.*",
127+
"org.junit.jupiter.api.DynamicContainer.*",
128+
"org.junit.jupiter.api.DynamicTest.*"
129+
],
130+
"importOrder": ["java", "javax", "com", "org"]
131+
}
132+
}
133+
}
134+
}
135+
}
136+
}
137+
}
98138
}
99139
```
100-
101-
*Example taken from JDTLS's [configuration options wiki page].*
102-
103-
You can see all the options JDTLS accepts [here][configuration options wiki page].
104-
105-
[JDTLS]: https://github.com/eclipse-jdtls/eclipse.jdt.ls
106-
[configuration options wiki page]: https://github.com/eclipse-jdtls/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
107-
[Lombok]: https://projectlombok.org

src/config.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ use crate::util::expand_home_path;
55
pub fn get_java_home(configuration: &Option<Value>, worktree: &Worktree) -> Option<String> {
66
// try to read the value from settings
77
if let Some(configuration) = configuration
8-
&& let Some(java_home) = configuration.pointer("/java/home").and_then(|x| x.as_str()) {
9-
match expand_home_path(worktree, java_home.to_string()) {
10-
Ok(home_path) => return Some(home_path),
11-
Err(err) => {
12-
println!("{}", err);
13-
}
14-
};
15-
}
8+
&& let Some(java_home) = configuration
9+
.pointer("/java_home")
10+
.or_else(|| configuration.pointer("/java/home")) // legacy support
11+
.and_then(|x| x.as_str())
12+
{
13+
match expand_home_path(worktree, java_home.to_string()) {
14+
Ok(home_path) => return Some(home_path),
15+
Err(err) => {
16+
println!("{}", err);
17+
}
18+
};
19+
}
1620

1721
// try to read the value from env
1822
match worktree
@@ -30,8 +34,9 @@ pub fn is_lombok_enabled(configuration: &Option<Value>) -> bool {
3034
.as_ref()
3135
.and_then(|configuration| {
3236
configuration
33-
.pointer("/java/jdt/ls/lombokSupport/enabled")
37+
.pointer("/lombok_support")
38+
.or_else(|| configuration.pointer("/java/jdt/ls/lombokSupport/enabled")) // legacy support
3439
.and_then(|enabled| enabled.as_bool())
3540
})
36-
.unwrap_or(false)
41+
.unwrap_or(true)
3742
}

0 commit comments

Comments
 (0)