Build your own Sourcegraph extensions

By Chris Wendt on October 15, 2018


We’re happy to announce that Sourcegraph extensions are ready for early adopters to start writing their own extensions.

Sourcegraph extensions allow you to extend code hosts like GitHub in the same way that editor extensions allow you to extend editors. Once you write an extension, it runs anywhere you see code (e.g. GitHub).

Here’s an extension that shows a tooltip when you hover over code:

import * as sourcegraph from "sourcegraph";

export function activate(): void {
  sourcegraph.languages.registerHoverProvider(["*"], {
    provideHover: () => ({ contents: { value: "Hello, world! 🎉🎉🎉" } })
  });
}

image

Here’s another extension that adds a link to the npm registry next to import/require statements in JavaScript/TypeScript code:

demo

When you publish your extension to the Sourcegraph.com extension registry, anyone can install and instantly start using it. (Sourcegraph Enterprise supports a private extension registry.)

Next steps:

Changelog since last alpha release

  • The new extension registry lets you browse and add any extension published on Sourcegraph
  • A new src extensions publish command for publishing Sourcegraph extensions
  • Sourcegraph instances can now have private extension registries extensions can be whitelisted on an Enterprise instance
  • Extensions can now run on diff pages
  • Created extension authoring documentation