Code navigation in GitHub pull requests

Quinn Slack

Code navigation helps you review code in GitHub pull requests more quickly and effectively.

  • Hovers show you documentation and type information for symbols.
  • Go to definition jumps you to where a function (or other symbol) is defined.
  • Find references lists everywhere a function (or other symbol) is called or used.

Here's what it looks like:

GitHub pull request demonstrating code navigation to help review code.

How does it help? Suppose you're reviewing a pull request that calls a function you don't recognize. You'll be able to quickly answer:

  • What does the function do, and are the arguments correct? Hover over it to see its documentation and signature.
  • Does the function expect its inputs to be sanitized? Go to its definition and find out by reading the source code.
  • Are we already calling this function? If so, are there any helper functions we could reuse? Any usage patterns we should follow for consistency? Find references to the function to get these answers.

Set it up

You'll need to use Sourcegraph because GitHub's code navigation doesn't work in pull requests. GitHub has no public plans to add support, but if it does, switching should be easy because Sourcegraph's underlying code intelligence for 20+ languages is open source, uses open standards (including Microsoft's LSP and LSIF), and is vendor neutral.

First: try it on a public repository (~1min)

  1. Install the Sourcegraph browser extension.
  2. Visit a pull request in any public repository, such as:
  3. Hover over a symbol in the pull request and press Go to definition or Find references.

Next: set it up for private code (~10min)

Next, run a Sourcegraph server yourself to use code navigation for your organization's private code (without sending any code to Sourcegraph).

  1. Follow the Sourcegraph docker run quickstart guide and add a GitHub external service with your private repositories.
  2. In your browser toolbar, open the Sourcegraph options menu by pressing the Sourcegraph icon (Sourcegraph icon) and set the Sourcegraph URL to http://localhost:7080 (the URL of your Sourcegraph instance).
  3. Visit a code file or pull request in a GitHub private repository.
  4. Hover over a symbol and press Go to definition or Find references.

That's it! Now deploy Sourcegraph for your team so everyone at your organization can use it.

Any other questions? File an issue or contact us.

About the author

Quinn Slack is the CEO and co-founder of Sourcegraph, the code intelligence platform for dev teams and making coding more accessible to more people. Prior to Sourcegraph, Quinn co-founded Blend Labs, an enterprise technology company dedicated to improving home lending and was an egineer at Palantir, where he created a technology platform to help two of the top five U.S. banks recover from the housing crisis. Quinn has a BS in Computer Science from Stanford, you can chat with him on Twitter @sqs.

Get Cody, the AI coding assistant

Cody makes it easy to write, fix, and maintain code.