簡體   English   中英

嘗試格式化我的 Java 代碼時出現“沒有安裝 'java' 文件的格式化程序”消息

[英]"There is no formatter for 'java' files installed" message when trying to format my Java code

今天網上看到的東西我試了無數次,就是無法得到RedHat Java 支持擴展來格式化代碼。 過去它曾經為我工作。 今天的某個時候,我完全卸載了 VS Code,以及 %APPDATA% 和 %USERPROFILE% 中的所有設置。 我重新安裝了它並安裝了Java 的擴展包(它也安裝了 RedHat),但它仍然無法正常工作。 我整天都在嘗試使用 settings.json 文件,但似乎沒有任何效果。 這些是我當前的設置:

{
"security.workspace.trust.untrustedFiles": "open",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.format.enabled": true,
"[java]": {
    "editor.defaultFormatter": "redhat.java"
},
"java.format.settings.url": "file:///[PathTo..]\\eclipse-formatter.xml",
"editor.defaultFormatter": "redhat.java"
}

我究竟做錯了什么?

您不需要添加file:///作為"java.format.settings.url"的值。 刪除此設置並閱讀它,看看它是否有幫助。

If not, delete formatter.xml in current opened project then click Java: Open Java Formatter Settings with Preview from Command Palette, create a default one, it will generate java-formatter.xml in the folder .vscode and settings.json will have

"java.format.settings.url": ".vscode/java-formatter.xml"

然后轉到 .java 文件和Format Document 因此,如果此默認設置有效,但您的eclipse-formatter.xml無效,請檢查它是否有問題。 或者你可以選擇java-formatter.xml因為它是一種 eclipse 格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM