Closed MLNW closed 1 year ago
Not sure about my answer, but I think it's because prettier-java is a community plugin, and not an official one:
As the project prettier-vscode is maintained directly by the prettier team, I think it's normal they didn't include Java.
@pascalgrimaud From their documentation I would expect it to work as the plugin is correctly loaded: https://github.com/prettier/prettier-vscode#plugins
This extension supports Prettier plugins when you are using a locally or globally resolved version of prettier. If you have Prettier and a plugin registered in your package.json, this extension will attempt to register the language and provide automatic code formatting for the built-in and plugin languages.
They also hint at it in this issue where they reference this plugin: https://github.com/prettier/prettier-vscode/issues/1124
@MLNW following up just in case.
I have it running with esbenp.prettier-vscode
.
Be sure to add the following to your .vscode/settings.json
:
"[java]": {
...
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
And be sure to restart after changing your .prettierrc too.
Starting from v2.2.0 of this plugin it works in my VS code. I guess that is due to the changes to plugin discovery made with prettier v3.0
Prettier-Java 2.1.0
I have a mono repo with a Java and a SvelteKit application. It's structure looks like this:
The
package.json
contains only prettier related dependencies:When I run
pnpm run format
it works as expected. Both Java and SvelteKit files are formatted correctly.Now I want to use these plugins from VS code. I install the
esbenp.prettier-vscode
plugin and try to format files in VS Code. Now I get this error:With debug mode enabled I see that the plugin is correctly found:
In VS Code I see this init message from prettier which does not include Java:
I scoured the web but was unable to find any solutions to this issue. There is also no more documentation pointing me in the right direction. I hope you can help me figure this issue out and resolve it.