VS Code and Python, isort doesn't do its job

3.1k Views Asked by At

I've installed black and isort for code formatting in VS Code. Black works while isort seems not to.

If I run isort from the command line there are no problems.

I've tried modifying setting.json to no avail. This is the latest version:

{
    "window.zoomLevel": 0,
    /** "editor.codeActionsOnSave": null */
    /** Enable format on save */
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        /** Pyformat use it's own code action to prevent confliction with other tools. */
        "source.organizeImports.pyformat": true,
        "source.organizeImports.python": true
    },
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "python.languageServer": "Pylance",
    /** "python.sortImports.path": "isort", */
    "python.sortImports.args": [
        "-m 3",
        "-tc",
        "-w 88"
    ],
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--line-length=88"
    ],
...

Any suggestions?

1

There are 1 best solutions below

0
On BEST ANSWER

VS Code only supports a single formatter being used at a time. There is however a workaround described in this answer:

const firstFormatter = commands.executeCommand('editor.action.formatDocument');

firstFormatter.then(() => myFormat());

I'd personally configure it to use black, then attach the command to run the second one.