Before debugging your extension, make sure of the following things:
activationEvents. (For example, extensions with
*are always activated. Extensions with
onLanguage:pythonare only activated when you view
src extensions publishcommand expects a
.mapfile next to your extension’s
For quick debugging, you can use
console.log (or other
If debugging on a code host e.g. GitHub, the extension runs as a background script. To view your
console.log statements, go to the background page in chrome://extensions. If you are unable to see a “Background page” link under the Sourcegraph extension then you need to enable Developer mode.
To set breakpoints and step through execution in your Sourcegraph extension:
console.logto your extension code and reload. Look in the devtools console for the log message, and then click on the filename where the log line was emitted (which is usually shown on the far right).
debugger;statement to your extension code and reload (with your browser devtools open). Execution will stop when your browser encounters that statement, and you’ll be dropped into the source file.
A Sourcegraph page uses an internal RPC protocol to communicate with extensions (which run in a Web Worker). This protocol consists of request-response sequences, such as “get the hover contents for
$POSITION” and the corresponding response with the hover message.
In rare cases, it helps to see the communication between Sourcegraph and your extension. This can help identify bugs in the Sourcegraph extension API itself.
To enable trace logging:
Trace log messages are logged via
console.log and appear in your browser’s devtools console.