Visual Studio Code extension bisect utility

February 16, 2021 by Johannes Rieken, @johannesrieken

“Just like git-bisect, but for VS Code extensions.”

The true power of Visual Studio Code is its extensions: theme extensions add colors and icons, language extensions enable smart code completion (IntelliSense) and navigation, debugger extensions enable you to run your code and easily find bugs. There are extensions that play music, some that show stock tickers, and there are extensions that enable collaborative work across locations and time zones. The VS Code Marketplace hosts more than 28,000 extensions and it is not uncommon that users have 50 or more extensions installed. With so many extensions out there, bugs are inevitable. Instead of denial, we want to make troubleshooting easy.

“Bad” extensions

We love extensions and don’t really think there are any “bad” extensions. However, like all software, extensions have bugs and feature gaps. So, for reading ease and artificial drama, let’s use the term “bad extensions”, which is an extension that might crash or simply show unwanted behavior. Fortunately, we designed VS Code with “bad” extensions in mind and therefore run them in a separate process. This isolation guarantees that the cursor always blinks and that you can always save your work.

For fun, and to make it easier to demonstrate extension bisect, we have created and published the Extension Bisect Demo extension. When installed, it will annoyingly reset your cursor whenever you reach the word “bisect”. You can use this extension to follow along in this blog post.

Finding a “bad” extension the hard way

Today, finding a “bad” extension can be easy or hard. Open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)), disable an extension, reload the window (Developer: Reload Window), and check to see if the problem still exists. If the problem is gone, that extension is “bad” and you are done. Otherwise, re-enable the extension and repeat the process with the next extension.

If you are lucky the first extension is the “bad” one; if you are unlucky, it’s the last extension. Using computer science language, this means with N extensions, you have a worst-case of repeating the process O(N) (order N), and an average-case of O(N/2). Because this algorithm is operated by a human (you), even small values of N are laborious. This is where the extension bisect utility comes in handy. It is much better in the worst and average cases because it disables extensions by halves.

Welcome extension bisect

The Extension bisect utility in VS Code was inspired by the git bisect command. For those familiar with Git, this command is helpful for finding out which commit in the repository introduced an issue.

Let’s use a sample: I have 24 extensions installed and the 8th extension is “bad”. We know that the iterative approach requires 8 steps. What about bisect?

The video below shows starting extension bisect via the Help: Start Extension Bisect command and then selecting either Good now or This is bad until the “bad” extension is identified. Once identified, you have the option to report an issue for that extension.

Here’s step by step how the “bad” extension was found:

Bisect divides 24 extensions into two halves of 12 extensions each, and it disables all 12 extensions of the second half. In this sample, the 8th

Continue reading

This post was originally published on this site