Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code not formatting due to "Extension 'JSON Language Features' cannot format file" error

I've got an error when trying to format my code in Visual Studio. I have the following plugins installed for the languages I use:

shell-format (bash)
Go           (golang)
PyFormat     (python)

I have also set up a keybinding SHIFT+ALT+F to format a file, with the when condition:

editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly

But whenever I use this shortcut (or use auto-format on save), nothing is formatted and I see this error in the toolbar at the bottom:

"Extension 'JSON Language Features' cannot format [filepath]"

I don't know what this extension even is, since I don't have any JSON-based extentions installed.

Has anyone else seen something similar?

like image 523
zodac Avatar asked Sep 14 '25 15:09

zodac


1 Answers

I just had this with Python, and it turned out the issue was that I had a line in my settings like this:

"editor.defaultFormatter": "vscode.json-language-features",

Since I wanted Python to use black. and it's that that wasn't working and giving me the same error message you're getting, I changed the line above so it was only relevant for json, and double checked formatters for other languages (don't forget to check settings for user, remote and workspace).

In the end, my settings for default formatting looked like this:

    "editor.formatOnSave": true,
    "[python]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports.python": true,
        }
    },
    "[django-html]": {
        "editor.formatOnSave": false,
    },
    "[vue]": {
        "editor.defaultFormatter": "octref.vetur"
    },
    "[json]": {
        "editor.defaultFormatter": "vscode.json-language-features",
    },

And presto, my Python format on save was working again.

I suspect your problem is the same, but post your settings.json if making that vscode.json-language-features json specific doesn't work ...

like image 94
michjnich Avatar answered Sep 17 '25 09:09

michjnich