Go LSIF Indexing

This guide is meant to provide specific instructions to get you producing index data in LSIF as quickly as possible for Go codebases.

Automated indexing

We provide the docker images sourcegraph/lsif-go and sourcegraph/src-cli to make automating this process in your favorite CI framework as easy as possible. Note that the lsif-go image bundles src-cli so the second image may not be necessary.

Here's some examples in a couple popular frameworks, just substitute the indexer and upload commands with what works for your project locally. If you end up implementing this in a different framework, feel free to edit this page with instructions!

GitHub Actions

on:
  - push

jobs:
  lsif-go:
    # this line will prevent forks of this repo from uploading lsif indexes
    if: github.repository == '<insert your repo name>'
    runs-on: ubuntu-latest
    container: sourcegraph/lsif-go:latest
    steps:
      - uses: actions/checkout@v1
      - name: Generate LSIF data
        run: lsif-go
      - name: Upload LSIF data
        # this will upload to Sourcegraph.com, you may need to substitute a different command.
        # by default, we ignore failures to avoid disrupting CI pipelines with non-critical errors.
        run: src code-intel upload -github-token=${{ secrets.GITHUB_TOKEN }} -ignore-upload-failure

The following projects have example GitHub Action workflows to generate and upload LSIF indexes.

CircleCI

version: 2.1

jobs:
  lsif-go:
    docker:
      - image: sourcegraph/lsif-go:latest
    steps:
      - checkout
      - run: lsif-go
        # this will upload to Sourcegraph.com, you may need to substitute a different command.
        # by default, we ignore failures to avoid disrupting CI pipelines with non-critical errors.
      - run: src code-intel upload -github-token=<<parameters.github-token>> -ignore-upload-failure

workflows:
  scip-typescript:
    jobs:
      - scip-typescript

The following projects have example CircleCI configurations to generate and upload LSIF indexes.

Travis CI

services:
  - docker

jobs:
  include:
    - stage: lsif-go
      # this will upload to Sourcegraph.com, you may need to substitute a different command.
      # by default, we ignore failures to avoid disrupting CI pipelines with non-critical errors.
      script:
      - |
        docker run --rm -v $(pwd):/src -w /src sourcegraph/lsif-go:latest /bin/sh -c \
          "lsif-go; src code-intel upload -github-token=$GITHUB_TOKEN -ignore-upload-failure"        

The following projects have example Travis CI configurations to generate and upload LSIF indexes.

Manual indexing

  1. Install lsif-go

  2. 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
    
    • macOS: replace linux with darwin in the URL, choose the appropriate architecture: M1/M2 chips - arm64, Intel chips - amd64
    • Windows: visit the CLI's repo for further instructions
  3. cd into your Go project's root (where the go.mod file lives, if you have one) and run:

    lsif-go # generates a file named dump.lsif
    
  4. Upload the data to a Sourcegraph instance with

    # for private instances
    src -endpoint=<your sourcegraph endpoint> lsif upload
    # for public instances
    src code-intel upload -github-token=<your github token>
    

The upload command will provide a URL you can visit to see the upload's status, and when it's done you can visit the repo and check out the difference in code navigation quality!