You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VSCode version 1.49 introduces a new "Only format modified text" option which only formats code that has been modified as reported by the version control system. Details of this change can be found on the official vscode release page.
However, users of the python extension cannot utilize this feature if they choose black as their code formatter, and attempts to do so result in an annoying prompt popping up after every save which states Black does not support the "Format Selection" command. This appears to be a somewhat long running issue and was previously reported in microsoft/vscode-black-formatter#176 , but up to this point had not effected many people as it only pops up the message when using the format selection command directly.
However, with this new VSCode change this error message pops up on every save unless you disable the feature entirely, which means you loose it for all other file types where it does function correctly. Regardless of the validity of the arguments from the black developers (as found in 134, 142, 245, 370, 511, 830) this is a very annoying popup to have displayed repeatedly and could be handled better.
There are several things that could be done to better handle this in my opinion. The first and simplest method is to provide the ability to disable this popup as discussed in microsoft/vscode-black-formatter#176. However, there are some other options to fix the behavior entirely.
One option would be to use something like akaihola/darker which essentially does the same thing as the "Only format modified text" option in vscode, but is black specific and has some additional features. This tool seems to work quite well in my experience, and does achieve the desired behavior, but still prevents using the only format modified text option for all other file types, which makes the solution suboptimal.
Another alternative is wbolster/black-macchiato which does similar things to the darker project, but is a bit more focused on black specifically and does not contain the extra features. I do not have any specific experience with this project, but it seems to perform the desired task.
I understand that this is an odd use case, and that the intent of black is to be run against all files all the time, however, there are many cases where one may wish to leave unmodified portions of the code base alone and not re-format them. the linked black issues above include many examples of cases where this behavior is desired, and at the end of the day, this feature was important enough to enough people that it was included in the main VSCode editor.
I'm personally unsure of the best path forward, and am not confident in declaring this as a bug since the behavior is technically desired, however, I see it as more significant due to the 1.49 changes as the error message will now be printed on every single save command (and if you have save on focus change enabled, every time you switch away from a file). That being said, I see this as something many people would use if implemented (look no further than 830 to see this for yourself).
The text was updated successfully, but these errors were encountered:
VSCode version 1.49 introduces a new "Only format modified text" option which only formats code that has been modified as reported by the version control system. Details of this change can be found on the official vscode release page.
However, users of the python extension cannot utilize this feature if they choose black as their code formatter, and attempts to do so result in an annoying prompt popping up after every save which states
Black does not support the "Format Selection" command
. This appears to be a somewhat long running issue and was previously reported in microsoft/vscode-black-formatter#176 , but up to this point had not effected many people as it only pops up the message when using the format selection command directly.However, with this new VSCode change this error message pops up on every save unless you disable the feature entirely, which means you loose it for all other file types where it does function correctly. Regardless of the validity of the arguments from the black developers (as found in 134, 142, 245, 370, 511, 830) this is a very annoying popup to have displayed repeatedly and could be handled better.
There are several things that could be done to better handle this in my opinion. The first and simplest method is to provide the ability to disable this popup as discussed in microsoft/vscode-black-formatter#176. However, there are some other options to fix the behavior entirely.
One option would be to use something like akaihola/darker which essentially does the same thing as the "Only format modified text" option in vscode, but is black specific and has some additional features. This tool seems to work quite well in my experience, and does achieve the desired behavior, but still prevents using the only format modified text option for all other file types, which makes the solution suboptimal.
Another alternative is wbolster/black-macchiato which does similar things to the darker project, but is a bit more focused on black specifically and does not contain the extra features. I do not have any specific experience with this project, but it seems to perform the desired task.
I understand that this is an odd use case, and that the intent of black is to be run against all files all the time, however, there are many cases where one may wish to leave unmodified portions of the code base alone and not re-format them. the linked black issues above include many examples of cases where this behavior is desired, and at the end of the day, this feature was important enough to enough people that it was included in the main VSCode editor.
I'm personally unsure of the best path forward, and am not confident in declaring this as a bug since the behavior is technically desired, however, I see it as more significant due to the 1.49 changes as the error message will now be printed on every single save command (and if you have save on focus change enabled, every time you switch away from a file). That being said, I see this as something many people would use if implemented (look no further than 830 to see this for yourself).
The text was updated successfully, but these errors were encountered: