Importing the Sourcegraph API module
In order to use the Sourcegraph extension API, your extension needs to import
sourcegraph module at the top of the file.
This import will look like this:
import * as sourcegraph from 'sourcegraph'
Or, with the equivalent
const sourcegraph = require('sourcegraph')
How the import works
Unlike a regular module that is installed with
yarn and is packaged
or bundled with your project, the
sourcegraph module is actually injected
dynamically when your extension is loaded within a Sourcegraph instance.
sourcegraph module that you install as a
package.json dependency is
actually a set of TypeScript type definitions that allow you to use the
Sourcegraph API’s interfaces. The module doesn’t contain the implementations of
sourcegraph module doesn’t actually contain any implementation
code, a separate helper module is provided to create stubs of the API for
See Testing extensions for more about writing automated tests for your extension.