I'm working on a project that uses Typescript and Java. The code formatting used for the code style is Intellij's default formatting. I am using vscode, so I would like to use Intellij's code formatting in vscode. Is there any way I can do this?
From IntelliJ, export the eclipse formatter file (XML) from settings > editor > Code style > Java
In Vscode you can download the extension - Language Support for Java™ by Red Hat which can import setting from XML files.
In Vscode > user - settings.json add the following
"java.format.enabled": true,
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
"[java]": {
"editor.defaultFormatter": "redhat.java"
}
you can replace the URL with the local file path or a GitHub XML raw file link (of the previously exported IntelliJ XML file)
for more information on the Vscode extension, you can refer following links
- https://code.visualstudio.com/docs/java/java-linting
- https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings
However, do note that there still might be differences in formatting between both IDEs (I think it's due to IntelliJ having a separate IntelliJ code style XML
along with Eclipse XML which overrides some rules).
I prefer to use the eclipse-java-google-style.xml on both IDEs as it seems more consistent while formatting.
© 2022 - 2024 — McMap. All rights reserved.