microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
150 stars 35 forks source link

Multi-root workspaces require all folders to a valid python interpreter #370

Closed ngtrunghuan closed 9 months ago

ngtrunghuan commented 11 months ago

When formatting a file in a folder with a valid interpreter, the extension failed due to the server not starting up. This seemed to be due to one of the folder not having a valid interpreter. The old black functionality under the ms-python.python extension however could function well.

Reproduction steps:

ms-python.black version v2023.6.0 ms-python.python version v2023.21.13101009

karthiknadig commented 11 months ago

@ngtrunghuan You can set folder b to use the same interpreter as folder A. Just set the black-formatter.interpreter to the one used by folder A. you can use this to refer to folder A ${workspaceFolder}:A where A is the name of the folder A.

karthiknadig commented 9 months ago

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

stefanhige commented 8 months ago

While the workaround with ${workspaceFolder:A} works, what if I have a multi-root workspace where the black formatter does not make sense for every folder (not every folder is a python project). Then I will have to define a python interpreter for every folder that is part of the multi-root workspace, just to make black formatter work for the one folder where I want to use it.

Could black formatter not only be available for those folders inside a multi-root workspace that provide all the necessary configuration?

karthiknadig commented 8 months ago

@stefanhige You only need to do this if you have different python versions for each workspace root. I general if you have a "Entire Workspace" python, that will be used. You only ever deal with this problem if you explicitly have different pythons per workspace root.