How do I use intellij's code formatter in vscode?
Asked Answered
C

1

11

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?

Clercq answered 21/2, 2021 at 15:56 Comment(1)
All you can do now is to export EditorConfig file in Settings -> Code Style -> gear icon -> Export, and import this to VSCode. Although this format has many limitations compared to Intellij formatEratosthenes
S
8

From IntelliJ, export the eclipse formatter file (XML) from settings > editor > Code style > Java enter image description here

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

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.

Subordinary answered 24/5, 2023 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.