Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug installed VSCode extensions?

In Atom, I'm able to debug installed extensions by opening the developer tools (Option+Cmd+I) and browsing through JavaScript files in ~/.atom/packages, e.g.

Atom developer tools

Is it possible to do this in VSCode? After opening the developer tools via Help -> Toggle Developer Tools, the only extension-related files I can find are the icon images:

VSCode developer tools

like image 362
Spencer Avatar asked Aug 17 '16 18:08

Spencer


People also ask

How do I debug a VS Code extension?

VS Code's built-in debugging functionality makes it easy to debug extensions. Set a breakpoint by clicking the gutter next to a line, and VS Code will hit the breakpoint. You can hover over variables in the editor or use the Run and Debug view in the left to check a variable's value.

How do I debug an extension?

Navigate to the chrome extensions management page at chrome://extensions and ensure developer mode is on. Click the Load Unpacked button and select the broken extension directory. After the extension is loaded, it should have three buttons: Details, Remove and Errors in red letters.

How do I see installed VS Code extensions?

Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.

Why my extensions are not working in VS Code?

The solution was to go to Windows PowerShell and open Visual Studio Code, then go to the extensions and restart the Remote - WSL extension, and go back to WSL. It then started working immediately.

How do I debug an extension in Visual Studio Code?

You can easily run your extension under the debugger by pressing F5. This opens a new VS Code window with your extension loaded. from your extension shows up in the Debug Console. You can set break points, step through your code, and inspect variables either in the

Does VS Code have a built-in debugger?

VS Code ships with one built-in debugger extension, the Node.js debugger extension, which is an excellent showcase for the many debugger features supported by VS Code: This screenshot shows the following debugging features:

How do I browse and install extensions in Visual Studio Code?

You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (⇧⌘X (Windows, Linux Ctrl+Shift+X)). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.

How does VS Code debug with the extension host?

Once the Extension Host is launched, VS Code attaches the debugger to it and starts the debug session. This is what happens when pressing F5 : 1. .vscode/launch.json instructs to first run a task named npm . 2. .vscode/tasks.json defines the task npm as a shell command to npm run compile . 3.


2 Answers

1. Find the extension host process's PID:

$ PID=$(pgrep -f "^/Applications/Visual Studio Code\.app/.*--type=extensionHost")
$ echo $PID
35791

Argument -f tells pgrep to match the pattern against the full process argument string, not just the process name.

2. Send SIGUSR1 to the extension host Node process to tell it to start listening for debugger connections:

$ kill -SIGUSR1 $PID

(This produces no output.)

3. Find which port the process started listening on using lsof:

$ lsof -p $PID -a -i4tcp
COMMAND     PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Code\x20H 35791 tim.vergenz   58u  IPv4 0x8af67df8a9aa26a8      0t0  TCP localhost:63767 (LISTEN)

Argument explanations:

  • -p means filter by PID
  • -i4tcp means filter by Internet address (4tcp means only IPv4 / tcp protocl)
  • the -a in between combines the two filters via AND instead of the default OR

In the "NAME" column you'll find the host and port that your VS Code extension host process is listening on -- i.e. in the example above, localhost:63767.

4. Open Chrome Devtools, and add the debug address under Devices > Discover network targets > Configure.

Chrome Devtools @ chrome://inspect

add debugger address from step 3

5. Open your new debug target:

connect to new debug target

You may need to manually add ~/.vscode/extensions to your workspace in order to browse files and add breakpoints:

add folder to workspace

... and click "Allow" to grant it permission:

allow devtools to access ~/.vscode/extensions

Success!

success! VS Code extensions now show in devtools

like image 194
vergenzt Avatar answered Oct 28 '22 06:10

vergenzt


Your code doesn't show in the main developer tools because VSCode unfortunately runs extensions in a separate process called the Extension Host.

You can go to Help > Process Explorer to look up the Extension Host process id, then kill -sigusr1 it to turn on its debugger (like any node process). Then in Chrome, go to chrome://inspect and you should see the process (it won't look very recognizable, the name will be something like /private/var/folders/f3/zmhpprp15zxfd1s3fpp3prm80000gn/T/AppTranslocation/C0D80599-1ECA-4802-A110-A1…)

I'm not 100% sure if all extension code is available in that debugger because it has subprocesses, but so far I've been able to set breakpoints in some of my installed extensions.

like image 2
Andy Avatar answered Oct 28 '22 05:10

Andy