Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black does not support the Format Selection command #8130

Closed
vsfeedback opened this issue Jan 7, 2025 · 5 comments
Closed

Black does not support the Format Selection command #8130

vsfeedback opened this issue Jan 7, 2025 · 5 comments
Assignees
Labels
waiting for upstream Waiting for upstream to release a fix

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:I'm unable to use this version]
(I would have been unable to use the default setup of VS without a deep dive into Google to find the answer)

Settings
I have GH Copilot and VsVim enabled in VS. I am working on a Python project. I have done no additional config.

Error
Every single thing I type prompts me nearly immediately with this dialogue box saying: Black does not support the Format Selection command.

Root Cause
Black formatter. VS takes what Copilot suggests and then tries to format it using Black with Format Selection instead of Format File?

Fix
Change the default formatter in VS from Black to PEP
"python.formatting.provider": "autopep8",
or
Tools -> Options -> Text Editor -> Python -> Formatting -> Formatter -> autopep8

How is no one else experiencing this? I basically just installed VS and did nothing else. I'm trying to evaluate it as a replacement for PyCharm, but I'm encountering a bunch of major, basic issues like this.


Original Comments

Feedback Bot on 1/6/2025, 11:27 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

@AdamYoblick
Copy link
Member

Black definitely doesn't support formatting a selection, it is designed to format the entire file. Perhaps VS and/or GH Copilot is assuming the default formatter can always be used to format the selection (the text just added, for example), which is not a valid assumption.

Let me try to reach out to the VS team to see what they say.

@AdamYoblick AdamYoblick added the waiting for upstream Waiting for upstream to release a fix label Jan 8, 2025
@captain-caveman2k
Copy link

captain-caveman2k commented Jan 9, 2025

I have been experiencing this for the last month as well, since I started using Github Co-Pilot in Visual Studio 2022 Professional.

I work as a C++ developer 90% of the time so I've simply ignored the issue whilst coding in Python - previous searches for a solution only revealed the error message in VS Code and not full Visual Studio.

Many thanks to the OP for the workaround - I can verify that changing the formatter for Python, and installing autopep8 solved the issue for me.

@Jean-Christophe21
Copy link

I also have the same Problem and I'm beginner visual studio . Please where i can change the default formatter in VS from Black to PEP

@AdamYoblick
Copy link
Member

To change the formatter through the VS menus, go to Tools -> Options -> Text Editor -> Python -> Formatting

Image

@StellaHuang95
Copy link
Contributor

Please see #8155. I have temporarily disabled the warning window as a workaround and filed an upstream ticket under Copilot team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for upstream Waiting for upstream to release a fix
Projects
None yet
Development

No branches or pull requests

6 participants