When you work with code that is deeply nested, it might get hard to know in what context the code is. You should follow good practices and not to create such a code, but sometimes the code is not yours or you are refactoring an old one. In such cases bracket, pair colorization comes in handy. Each bracket pair gets a different color, so you will have an easier job to orient yourself.
Here is an example without bracket pair colorization:
Here is an example with bracket pair colorization:
I suppose this is a matter of personal preference, but I do like the second example better.
The first implementation of bracket pair coloring was introduced by a user named CoenraadS as an extension for VS Code in 2016. Ultimately this led VS Code team to create native support for bracket pair colorizing, which was released in August 2021. The main reason for this step was performance. VS Code API didn't allow the creation of such a feature as an extension with high performance in mind. You can read more about it on the official blog https://code.visualstudio.com/blogs/2021/09/29/bracket-pair-colorization. And what's even better is that this feature is supported in VS Code for the Web as well.
For comparison, I include the same snippet as above with the default dark VSCode theme (Dark+):
It didn't take long for users of Visual Studio to desire this feature as well. The feature request appeared on Developer Community - Please vote up :-)
The standard process to introduce a new feature for Visual Studio takes some time. But since VS team is lucky to have Mads Kristensen - he created an extension that supports bracket pair colorization - called Rainbow Braces. The project is hosted on Github and it supports Visual Studio 2022.
We wanted to make sure that PHP Tools for Visual Studio supports it and we've quickly released an update that enables bracket pair colorization for PHP code as well. If you'd like to turn it on, make sure to use version 1.67.16259
or higher.
Then install Rainbow Braces extension version 1.0.34
or higher from VS Marketplace or directly withing Visual Studio, go to Extensions | Manage Extensions
and type rainbow braces
and click Download
.
If you wonder whether it's possible to customize the default colors, just go to Tools | Options
and choose Fonts and Colors
.
Or you can even turn on/off certain bracket pairs, in the Rainbow Braces
sub-item of Fonts and Colors
.
Thank you for your attention. Do you like this feature? Make sure to vote or comment on the original feature request Or is there something else in PHP code that deserves a color? Please let us know in the comments below.!