Vscode-java: There is no formatter for 'java' files installed

Created on 19 Jun 2020  Â·  4Comments  Â·  Source: redhat-developer/vscode-java

Hi,

I have imported an Eclipse format XML file to vscode follow your instruction in here
https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings
But it didn't work. Before that, it used to work great.
Just reinstall the vscode with java extension pack and start to meet this problem
I really want to stay with vscode to work with Java and don't want to come back to IntelliJ or Eclipse
Can you help me?

Thank you.

Environment
  • Operating System: Ubuntu 18.04.4 LTS
  • JDK version: 1.8.0_241
  • Visual Studio Code version: 1.46.1
    cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
    x64
  • Java extension version:
    Java Extension Pack v0.9.1
    include Language support for Java â„¢ v0.63.0
Steps To Reproduce
  1. install vscode from deb package
  2. install Java Extension Pack
  3. config file path of Eclipse_Formatter.xml
    "java.format.settings.url": "/home/dchoa/workspace/JavaFormatterEclipse.xml"
  4. try to format java file using Ctrl + Shift + I
Current Result

meet the error: There is no formatter for 'java' files installed

Expected Result

It should work like this

    @Override
    public void run() {
    try {
        wm.startWork( new TheWork() );
    } catch ( WorkException we ) {
        logger.error( "problem running worker thread ", we );
    }
    }
Additional Informations
  • Ctrl + Shift + P: >Java: Open Java formatter settings
    it still can open the Eclipse format xml file

  • "java.format.enabled": false
    when it is "true", it uses the default format, so I let it "false" as default

  • my setting.json (user settings)

{
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "workbench.startupEditor": "newUntitledFile",
    "editor.minimap.enabled": false,
    "window.zoomLevel": -1,
    "workbench.iconTheme": "material-icon-theme",
    "[java]": {},
    "java.configuration.checkProjectSettingsExclusions": false,
    "java.requirements.JDK11Warning": false,
    "java.semanticHighlighting.enabled": true,
    "java.format.enabled": false,
    "java.completion.favoriteStaticMembers": [
        "org.junit.Assert.*",
        "org.junit.Assume.*",
        "org.junit.jupiter.api.Assertions.*",
        "org.junit.jupiter.api.Assumptions.*",
        "org.junit.jupiter.api.DynamicContainer.*",
        "org.junit.jupiter.api.DynamicTest.*",
        "org.mockito.Mockito.*",
        "org.mockito.ArgumentMatchers.*",
        "org.mockito.Answers.*"
    ],
    "java.format.settings.url": "/home/dchoa/workspace/JavaFormatterEclipse.xml"
}

Most helpful comment

I'm not sure if this is only an option on the insiders version of vscode or if it is available in the release version. Try the following:

"[java]": {
    "editor.defaultFormatter": "redhat.java"
}

All 4 comments

I'm not sure if this is only an option on the insiders version of vscode or if it is available in the release version. Try the following:

"[java]": {
    "editor.defaultFormatter": "redhat.java"
}

I have tried your solution, it still not work for me :(

Apparently you turned off the formatter by "java.format.enabled": false, that's why you see the message "There is no formatter for 'java' files installed". Please enable that setting.

Thank @testforstephen @astrelsky
After edit "java.format.enabled": true
and put

"[java]": {
    "editor.defaultFormatter": "redhat.java"
}

It works again perfectly, I think the defaultFormatter should be configured to redhat.java right after the plugin was installed will be better

Thanks again for your support.

Was this page helpful?
0 / 5 - 0 ratings