Replies: 1 comment 1 reply
-
@gluxon This is awesome -- TY! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
I've been running into a strange GitLens issue (#3066) for a long time, but had trouble nailing it down since the problem was always intermittent and I wasn't able to reproduce it in a Extension Development Window. When the problem did reproduce, it went away with a extension host restart, removing the repro.
Goal
It should be possible to take any production built VS Code window running an extension like GitLens and debug it without a restart that may lose the bad state. I recently worked through how to do this and wanted to write it down somewhere for others (and my future self).
Disclaimers
Let's dive in!
Finding the VS Code Extension Host Process Port
The usual trick for debugging a
node
process is to send it theSIGUSR1
signal.The VS Code extension host process seems to listen on a less deterministic port than
node
processes out of the box. Fortunately VS Code makes it easy to attach itself to its own extension host.Hit the circle button to start profiling the extension host. Then hit the play button to the left to attach to the process. (Without hitting the profile button first, VS Code offers to restart the extension host.)
To attach Chrome's Node.js inspector, we'll need the port the process is listening on. In the debug console, we can enter:
The port for this process is
56929
.Attaching Chrome
At
chrome://inspect
, we'll add the port discovered above.This gives a new Inspect button.
From here, we can search for files loaded into the process. For GitLens, one file of interest is the bundled
gitlens.js
file.Checking Out Source
The above allows us to interactively debug
gitlens.js
, but this file is hard to understand since it's bundled and minified. We can GitLen's source code to make this easier. To do so, we'll want to check out the source for the exact version of GitLens we're using.Let's make a small tweak to GitLen's
webpack.config.js
to create a production build with source maps. We'll want to usehidden-source-map
to output our owngitlens.js
file that matches the currently running one.To build GitLens for production:
As an optional sanity check, we can make sure the built
gitlens.js
files are the same as what VS Code is running. If there are mismatches, the source code cloned could be subtly different than the original source of the loadedgitlens.js
file, which would cause breakpoints to mismatch and other oddities when debugging.Adding Source Maps to Chrome's Inspector
Let's teach Chrome about our built
dist/gitlens.js.map
. We'll need the absolute path of this file.Back in the Chrome inspector, we can right click anywhere in
gitlens.js
to "Add source map..."Finally, let's add our cloned
vscode-gitlens
directory to make file navigation easier. Hit "Add folder" on the left sidebar.Profit
It works! Note that the files loaded into Chrome on the left have green circles indicating their source maps are correctly associated with the generated
gitlens.js
production build.Beta Was this translation helpful? Give feedback.
All reactions