feat: Add google-java-format and palantir-java-format support#264
feat: Add google-java-format and palantir-java-format support#264fredyw wants to merge 1 commit into
Conversation
Integrates [google-java-format](https://github.com/google/google-java-format) and [palantir-java-format](https://github.com/palantir/palantir-java-format) support into the LSP proxy wrapper using a generic `Formatter trait` by intercepting document formatting requests at the LSP proxy layer. Key architecture and features: 1. Introduces generic `Formatter` to allow future formatting backends to be plugged in easily. 2. Automatically downloads `google-java-format` binaries from GitHub Releases and `palantir-java-format` binaries from Maven Central. 3. Intercepts `textDocument/formatting` requests, retrieves the document from the cache, spawns the formatter command, and responds with the replaced document changes. 4. Add supports for runtime toggling and hot-swapping formatters dynamically by listening to configuration notifications.
|
Thanks for the PR but is this really needed? What are the benefits of including these two specific formatters? |
|
The XML option is basically using Eclipse formatter that tries to match Google Java Style or Palantir Java Style (fork of Google Java Format). It's an approximation and never 100% the same. Ideally when we code and when we run it in CI (using spotless for instance), we want the formatting to be 100% compatible to reduce friction for developers. The option to use the Eclipse formatter still exists for those that prefer that. It's just an additional feature that I thought might benefit others. |
|
I see, I assumed that the end result of those formatters was the xml then consumed by JDTLS. Rather than integrating in the proxy the two formatters we could follow a different approach, similar to what Zed is doing with Ruff, for example. "Python": {
"code_actions_on_format": {
"source.organizeImports.ruff": true,
},
"formatter": {
"language_server": {
"name": "ruff",
},
},
"debuggers": ["Debugpy"],
"language_servers": ["basedpyright", "ruff", "!ty", "!pyrefly", "!pyright", "!pylsp", "..."],
}We vend from the extension the two LSP implementations wrapping the formatters and then the user, in order to enable them, uses the Java language settings, rather than the one for the extension, setting a different language server whose job is to format the code. I see some clear benefits following this path:
I'm happy to further discuss about this. |
Integrates google-java-format and palantir-java-format support into the LSP proxy wrapper using a generic
Formatter traitby intercepting document formatting requests at the LSP proxy layer.Key architecture and features:
Formatterto allow future formatting backends to be plugged in easily.google-java-formatbinaries from GitHub Releases andpalantir-java-formatbinaries from Maven Central.textDocument/formattingrequests, retrieves the document from the cache, spawns the formatter command, and responds with the replaced document changes.