Skip to content

Commit 38633a9

Browse files
authored
Update the README (#205)
1 parent 5b5829b commit 38633a9

1 file changed

Lines changed: 170 additions & 65 deletions

File tree

README.md

Lines changed: 170 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -75,89 +75,194 @@ To get started with Java, click the `edit debug.json` button in the Debug menu,
7575

7676
You should then be able to start a new Debug Session with the "Launch Debugger" scenario from the debug menu.
7777

78+
### Single-File Debugging
79+
80+
If you're working a lot with single file debugging, you can use the following `debug.json` config instead:
81+
```jsonc
82+
[
83+
{
84+
"label": "Debug $ZED_STEM",
85+
"adapter": "Java",
86+
"request": "launch",
87+
"mainClass": "$ZED_STEM",
88+
"build": {
89+
"command": "javac -d . $ZED_FILE",
90+
"shell": {
91+
"with_arguments": {
92+
"program": "/bin/sh",
93+
"args": ["-c"]
94+
}
95+
}
96+
}
97+
}
98+
]
99+
```
100+
This will compile and launch the debugger using the currently selected file as the entry point.
101+
Ideally, we would implement a run/debug option directly in the runnables (similar to how the Rust extension does it), which would allow you to easily start a debugging session without explicitly updating the entry point.
102+
Note that integrating the debugger with runnables is currently limited to core languages in Zed, so this is the best workaround for now.
103+
78104
## Launch Scripts (aka Tasks) in Windows
79105

80106
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.
81107

82108
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.
83109

84110
## Advanced Configuration/JDTLS initialization Options
85-
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:
111+
JDTLS provides many configuration options that can be passed via the `initialize` LSP-request. The extension will pass the JSON-object from `lsp.jdtls.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 opinionated example configuration for JDTLS with most options enabled:
86112

87113
```jsonc
88-
{
89-
"lsp": {
90-
"jdtls": {
114+
"lsp": {
115+
"jdtls": {
116+
"initialization_options": {
117+
"bundles": [],
118+
"workspaceFolders": [
119+
"file:///home/snjeza/Project"
120+
],
91121
"settings": {
92-
// this will be sent to JDTLS as initializationOptions:
93-
"initialization_options": {
94-
"bundles": [],
95-
// use this if your zed project root folder is not the same as the java project root:
96-
"workspaceFolders": ["file:///home/snjeza/Project"],
97-
"settings": {
98-
"java": {
99-
"home": "/usr/local/jdk-9.0.1",
100-
"errors": {
101-
"incompleteClasspath": {
102-
"severity": "warning"
103-
}
104-
},
105-
"configuration": {
106-
"updateBuildConfiguration": "interactive",
107-
"maven": {
108-
"userSettings": null
109-
}
110-
},
111-
"import": {
112-
"gradle": {
113-
"enabled": true
114-
},
115-
"maven": {
116-
"enabled": true
117-
},
118-
"exclusions": [
119-
"**/node_modules/**",
120-
"**/.metadata/**",
121-
"**/archetype-resources/**",
122-
"**/META-INF/maven/**",
123-
"/**/test/**"
124-
]
125-
},
126-
"referencesCodeLens": {
127-
"enabled": false
128-
},
129-
"signatureHelp": {
130-
"enabled": false
131-
},
132-
"implementationCodeLens": "all",
133-
"format": {
122+
"java": {
123+
"configuration": {
124+
"updateBuildConfiguration": "automatic",
125+
"runtimes": []
126+
},
127+
"saveActions": {
128+
"organizeImports": true
129+
},
130+
"compile": {
131+
"nullAnalysis": {
132+
"mode": "automatic"
133+
}
134+
},
135+
"references": {
136+
"includeAccessors": true,
137+
"includeDecompiledSources": true
138+
},
139+
"jdt": {
140+
"ls": {
141+
"protobufSupport": {
134142
"enabled": true
135143
},
136-
"saveActions": {
137-
"organizeImports": false
138-
},
139-
"contentProvider": {
140-
"preferred": null
141-
},
142-
"autobuild": {
143-
"enabled": false
144-
},
145-
"completion": {
146-
"favoriteStaticMembers": [
147-
"org.junit.Assert.*",
148-
"org.junit.Assume.*",
149-
"org.junit.jupiter.api.Assertions.*",
150-
"org.junit.jupiter.api.Assumptions.*",
151-
"org.junit.jupiter.api.DynamicContainer.*",
152-
"org.junit.jupiter.api.DynamicTest.*"
153-
],
154-
"importOrder": ["java", "javax", "com", "org"]
144+
"groovySupport": {
145+
"enabled": true
146+
}
147+
}
148+
},
149+
"eclipse": {
150+
"downloadSources": true
151+
},
152+
"maven": {
153+
"downloadSources": true,
154+
"updateSnapshots": true
155+
},
156+
"autobuild": {
157+
"enabled": true
158+
},
159+
"maxConcurrentBuilds": 1,
160+
"inlayHints": {
161+
"parameterNames": {
162+
"enabled": "all"
163+
}
164+
},
165+
"signatureHelp": {
166+
"enabled": true,
167+
"description": {
168+
"enabled": true
169+
}
170+
},
171+
"format": {
172+
"enabled": true,
173+
"settings": {
174+
// The formatter config to use
175+
"url": "~/.config/jdtls/palantir_java_jdtls.xml"
176+
},
177+
"onType": {
178+
"enabled": true
179+
}
180+
},
181+
"contentProvider": {
182+
"preferred": null
183+
},
184+
"import": {
185+
"gradle": {
186+
"enabled": true,
187+
"wrapper": {
188+
"enabled": true
155189
}
190+
},
191+
"maven": {
192+
"enabled": true
193+
},
194+
"exclusions": [
195+
"**/node_modules/**",
196+
"**/.metadata/**",
197+
"**/archetype-resources/**",
198+
"**/META-INF/maven/**",
199+
"/**/test/**"
200+
]
201+
},
202+
"completion": {
203+
"enabled": true,
204+
"favoriteStaticMembers": [
205+
"org.junit.Assert.*",
206+
"org.junit.Assume.*",
207+
"org.junit.jupiter.api.Assertions.*",
208+
"org.junit.jupiter.api.Assumptions.*",
209+
"org.junit.jupiter.api.DynamicContainer.*",
210+
"org.junit.jupiter.api.DynamicTest.*",
211+
"org.mockito.Mockito.*",
212+
"org.mockito.ArgumentMatchers.*"
213+
],
214+
"importOrder": [
215+
"java",
216+
"javax",
217+
"com",
218+
"org"
219+
],
220+
"postfix": {
221+
"enabled": true
222+
},
223+
"chain": {
224+
"enabled": true
225+
},
226+
"guessMethodArguments": "insertParameterNames",
227+
"overwrite": true
228+
},
229+
"errors": {
230+
"incompleteClasspath": {
231+
"severity": "warning"
156232
}
233+
},
234+
"implementationCodeLens": "all",
235+
"referencesCodeLens": {
236+
"enabled": true
157237
}
158238
}
159239
}
160240
}
161241
}
162242
}
163243
```
244+
245+
If you're working without a Gradle or Maven project, and the following error `The declared package "Example" does not match the expected package ""` pops up, consider adding these settings under
246+
247+
```
248+
MyProject/
249+
├── .zed/
250+
│ └── settings.json
251+
```
252+
253+
```jsonc
254+
"lsp": {
255+
"jdtls": {
256+
"initialization_options": {
257+
"project": {
258+
"sourcePaths": [
259+
".",
260+
"src"
261+
]
262+
},
263+
}
264+
}
265+
}
266+
```
267+
268+
If changes are not picked up, clean JDTLS' cache (from a java file run the task `Clear JDTLS cache`) and restart the language server

0 commit comments

Comments
 (0)