How to enable in vscode
I read all the guides still im puzzled how to enable the plugin in vscode.
I execute
npm install --save-dev --save-exact prettier prettier-plugin-java
I have the prettier extension installed.
and now ? how can i enable the formatting ? Still my other java formatter is executed by default. Format Document with... action does not detect it.
when i put
"[java]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
in settings.json
i get
How to link the plugin to formatting action ?
Hello @stephan-klein !
Do you have a Prettier configuration file ? If not, can you try creating one like this one (you can convert this one from yaml to any other format) and see if if fixes your issue ?
# Prettier configuration
plugins:
- prettier-plugin-java
overrides:
- files:
- "*.java"
options:
printWidth: 100
tabWidth: 4
useTabs: false
trailingComma: "none"
Also note that there is a regression in the latest version 2.6.6 that prevents Vscode to load the prettier-plugin-java plugin: https://github.com/jhipster/prettier-java/issues/711.
You either need to downgrade to 2.6.5 or update node_modules/prettier-plugin-java/package.json with the code mentioned in the linked issue.
I'm seeing the same error as OP. I usually run this via Spotless Maven plugin when committing but would be great to be able to format in the editor too.
I have a .prettier-java.json file similar to the yaml above in my project/backend dir and have the same VSCode settings config.
The prettier formatter works fine on other file formats, just not Java. Any help would be much appreciated, thanks!