Code navigation in GitHub pull requests
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:
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)
- Install the Sourcegraph browser extension.
- Visit a pull request in any public repository, such as:
- 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).
- Follow the Sourcegraph
docker runquickstart guide and add a GitHub external service with your private repositories.
- In your browser toolbar, open the Sourcegraph options menu by pressing the Sourcegraph icon () and set the Sourcegraph URL to
http://localhost:7080(the URL of your Sourcegraph instance).
- Visit a code file or pull request in a GitHub private repository.
- Using GitHub Enterprise Server? You'll need to grant permissions on its domain.
- 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.
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.