Manually index a popular Go repository
This tutorial shows you how to add LSIF data for a Go repository on your Sourcegraph instance to get precise code intelligence results.
Every time you add a repository to your Sourcegraph instance you automatically get fuzzy code intelligence results out of the box.
This can, in most cases, be good enough, but you may want to get precise results. By adding LSIF data for your repository you’ll be able to get precise results like shown below:
We recommend that use the latest version of Sourcegraph and that you have a basic understanding of how code intelligence works. See the following documents for more information:
For the purposes of the tutorial we’ll be using the following repository: https://github.com/moby/moby
Before starting this tutorial, you should first “Add the repository to Sourcegraph”.
Clone the Go repository locally
Clone the Go repository by running:
git clone https://github.com/moby/moby
Install Sourcegraph CLI
Install the Sourcegraph CLI with
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
curl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src chmod +x /usr/local/bin/src
brew install sourcegraph/src-cli/src-cli
Install the lsif-go indexer
Install the indexer by running:
curl -L https://github.com/sourcegraph/lsif-go/releases/download/v1.2.0/src_linux_amd64 -o /usr/local/bin/lsif-go chmod +x /usr/local/bin/lsif-go
curl -L https://github.com/sourcegraph/lsif-go/releases/download/v1.2.0/src_darwin_amd64 -o /usr/local/bin/lsif-go chmod +x /usr/local/bin/lsif-go
Run the indexer in the repo
Navigate to the repo’s root folder and run
dump.lsiffile should have been generated. This is the file you are going to upload to your Sourcegraph instance.
Upload the LSIF data file to your Sourcegraph instance
Go back to your terminal and make sure you are at the repo’s root folder (where the
dump.lsiffile is). Run:
src -endpoint=<your sourcegraph endpoint> lsif upload
If you open the processing status URL you will see the current status of your upload. Wait for it to complete.
You’ve indexed your first Go repo! You can now go to any Go file in that repo and get precise code intelligence results.
To learn what else you can do with Code Intelligence, see “Code intelligence”.