You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+116Lines changed: 116 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -246,6 +246,122 @@ If your project uses custom or internal Maven repositories, you should point JDT
246
246
247
247
Without this, JDTLS's embedded Maven will only resolve artifacts from Maven Central, which will cause unresolved dependency errors for projects using internal or private repositories.
248
248
249
+
## External Formatters
250
+
251
+
If you prefer to use an external formatting tool like `google-java-format` or `palantir-java-format` instead of the built-in Eclipse formatter, you can configure Zed to run these tools on save or format commands.
252
+
253
+
### Configuring google-java-format
254
+
255
+
To use `google-java-format` as your external formatter:
256
+
257
+
1.**Installation**: Download the pre-built native binary for your platform from the [GitHub releases page](https://github.com/google/google-java-format/releases). Place it in a directory that is in your system's `PATH` (e.g., `/usr/local/bin` or `~/.local/bin`), rename it to `google-java-format` (or `google-java-format.exe` on Windows), and ensure it is marked as executable.
258
+
- Alternatively, on macOS, you can install it via Homebrew: `brew install google-java-format`
259
+
2. Add the configuration to your Zed `settings.json`:
260
+
261
+
```json
262
+
"languages": {
263
+
"Java": {
264
+
"formatter": {
265
+
"external": {
266
+
"command": "google-java-format",
267
+
"arguments": ["-"]
268
+
}
269
+
}
270
+
}
271
+
}
272
+
```
273
+
274
+
If you prefer to format using the AOSP style (4-space indentation), you can pass the `--aosp` flag:
275
+
276
+
```json
277
+
"languages": {
278
+
"Java": {
279
+
"formatter": {
280
+
"external": {
281
+
"command": "google-java-format",
282
+
"arguments": ["--aosp", "-"]
283
+
}
284
+
}
285
+
}
286
+
}
287
+
```
288
+
289
+
If you installed it to a custom location not on your `PATH`, specify the absolute path for the `command`:
290
+
291
+
```json
292
+
"languages": {
293
+
"Java": {
294
+
"formatter": {
295
+
"external": {
296
+
"command": "/path/to/google-java-format",
297
+
"arguments": ["-"]
298
+
}
299
+
}
300
+
}
301
+
}
302
+
```
303
+
304
+
### Configuring palantir-java-format
305
+
306
+
To use `palantir-java-format` as your external formatter:
307
+
308
+
1.**Installation**:
309
+
-**macOS / Linux**: Download the native binary for your architecture from the [Maven Central repository page](https://repo1.maven.org/maven2/com/palantir/javaformat/palantir-java-format-native/). Rename it to `palantir-java-format`, mark it as executable, and place it in a directory in your system's `PATH`.
310
+
-**Windows**: Palantir does not distribute official pre-built native binaries for Windows. You must compile the native executable yourself from [palantir-java-format repository](https://github.com/palantir/palantir-java-format).
311
+
2. Add the configuration to your Zed `settings.json` (note that the `--palantir` option is required):
312
+
313
+
```json
314
+
"languages": {
315
+
"Java": {
316
+
"formatter": {
317
+
"external": {
318
+
"command": "palantir-java-format",
319
+
"arguments": ["--palantir", "-"]
320
+
}
321
+
}
322
+
}
323
+
}
324
+
```
325
+
326
+
### Running Formatters via JAR File (Alternative)
327
+
328
+
If a native executable is not available for your platform (or you prefer not to compile/install one), you can run the formatters using their `.jar` files (e.g. the all-deps/shadow JARs) by configuring Zed to launch `java` directly:
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.
0 commit comments