vscode: Default formatter not setting is not preserved when using devcontainer

Hi,

when adding the Black Formatter extension (version v2023.4.1) to devcontainer.json and configuring it like so:

"python.formatting.provider": "none",
"[python]": {
	"editor.formatOnSave": true,
	"editor.defaultFormatter": "ms-python.black-formatter"
}

when building the container I still get a warning that multiple formatters are detected and that a default formatter is not selected. Opening devcontainer.json says “Value is not accepted”, as if the extension is not properly loaded (even though it appears to be).

Screenshot from 2023-08-07 12-00-17

Selecting a default formatter in the Select default formatter dialog (even though one is already set in config) does nothing at all. However, if I select Format Document and then Black Formatter when asked to select default formatter, it does format the file. Again, the selection is not stored, however. What does fix the issue is selecting “Developer: Reload window”. That fixes the problem every time and things work like normal until next time the VSCode is launched or the container is rebuilt. It seems like the extension is not properly loaded the first time?

Some logs are pasted below, please let me know what else I can do to help debug this.

Black extension output
2023-08-07 10:05:29.003 [info] Name: Black Formatter
2023-08-07 10:05:29.003 [info] Module: black
2023-08-07 10:05:29.003 [info] Python extension loading
2023-08-07 10:05:29.003 [info] Waiting for interpreter from python extension.
2023-08-07 10:05:29.003 [info] No interpreter found from setting black-formatter.interpreter
2023-08-07 10:05:29.003 [info] Getting interpreter from ms-python.python extension for workspace /project
2023-08-07 10:05:29.003 [info] Python extension loaded
2023-08-07 10:05:29.003 [info] Interpreter from ms-python.python extension for /project: /software/venv/bin/python
2023-08-07 10:05:29.003 [info] No interpreter found from setting black-formatter.interpreter
2023-08-07 10:05:29.003 [info] Getting interpreter from ms-python.python extension for workspace /project
2023-08-07 10:05:29.003 [info] Interpreter from ms-python.python extension for /project: /software/venv/bin/python
2023-08-07 10:05:29.003 [info] Server run command: /software/venv/bin/python /home/dockeruser/.vscode-server/extensions/ms-python.black-formatter-2023.4.1/bundled/tool/lsp_server.py
2023-08-07 10:05:29.003 [info] Server: Start requested.
2023-08-07 10:05:29.519 [info] CWD Server: /project
2023-08-07 10:05:29.519 [info] Settings used to run Server:
[
    {
        "cwd": "/project",
        "workspace": "file:///project",
        "args": [
            "-l 100"
        ],
        "path": [],
        "interpreter": [
            "/software/venv/bin/python"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off"
    }
]

2023-08-07 10:05:29.519 [info] Global settings: { “cwd”: “/vscode/vscode-server/bin/linux-x64/6445d93c81ebe42c4cbd7a60712e0b17d9463e97”, “workspace”: “/vscode/vscode-server/bin/linux-x64/6445d93c81ebe42c4cbd7a60712e0b17d9463e97”, “args”: [], “path”: [], “interpreter”: [], “importStrategy”: “useBundled”, “showNotifications”: “off” }

2023-08-07 10:05:29.520 [info] sys.path used to run Server: /home/dockeruser/.vscode-server/extensions/ms-python.black-formatter-2023.4.1/bundled/libs /home/dockeruser/.vscode-server/extensions/ms-python.black-formatter-2023.4.1/bundled/tool /project/src /usr/lib/python38.zip /usr/lib/python3.8 /usr/lib/python3.8/lib-dynload /software/venv/lib/python3.8/site-packages 2023-08-07 10:05:29.521 [info] /software/venv/bin/python -m black --version 2023-08-07 10:05:29.521 [info] CWD formatter: /project 2023-08-07 10:05:29.680 [info] Version info for formatter running for /project: black, 23.3.0 (compiled: no) Python (CPython) 3.8.10

2023-08-07 10:05:29.681 [info] SUPPORTED black>=22.3.0 FOUND black==23.3.0

Python extension output
2023-08-07 10:05:27.925 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-08-07 10:05:27.925 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-08-07 10:05:27.925 [info] Test server listening.
2023-08-07 10:05:27.925 [info] Python interpreter path: /software/venv/bin/python
2023-08-07 10:05:30.064 [info] Starting Pylance language server.

VSCode version:

Version: 1.81.0
Commit: 6445d93c81ebe42c4cbd7a60712e0b17d9463e97
Date: 2023-08-02T12:36:11.334Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 5.19.0-50-generic

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 10
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Upgrading to version 1.81.1 seems to have solved it for me.

1.81.1 doesn’t seem to fix the issue for me. Whenever I rebuild the devcontainer I have to then execute Developer: Reload Window in order for the Black formatter to be recognized by the settings.

  1. Add the Black Formatter extension to devcontainer.json
  2. Put this into .vscode/settings.json:
"[python]": {
	"editor.formatOnSave": true,
	"editor.defaultFormatter": "ms-python.black-formatter"
}
  1. Build the container
  2. Create a Python script
  3. Run Format Document. expected: Formats document with Black. actual Asks to select a formatter