This quickstart guide will walk you through installing and generating LSIF data locally on your machine, and then manually uploading the LSIF data to your Sourcegraph instance for your repository. This will let you experiment with the process locally, and test your generated LSIF data on your repository before changing your CI process.
src) - used for uploading LSIF data to your Sourcegraph instance.
An LSIF indexer is a command line tool that analyzes your project’s source code and generates a file in LSIF format containing all the definitions, references, and hover documentation in your project. That LSIF file is later uploaded to Sourcegraph to provide code intelligence.
You now need to generate the LSIF data for your repository. Each language’s LSIF is unique to that language, so run the command in the generate LSIF data step found in the README of the installed indexer.
For all languages, the upload step is the same. Make sure the current working directory is somewhere inside your repository, then use the Sourcegraph CLI to run:
$ src \ -endpoint=https://sourcegraph.example.com \ lsif upload \ -file=<LSIF file (e.g. ./cmd/dump.lsif)>
If successful, you’ll see the following message:
Repository: <location of repository> Commit: <40-character commit associated with this LSIF upload> File: <LSIF data file> Root: <subdirectory in the repository where this LSIF dump was generated> LSIF dump successfully uploaded. It will be converted asynchronously. To check the status, visit <link to your Sourcegraph instance LSIF status>
Possible errors include:
-endpointand make sure you can view the repository on your Sourcegraph instance
true(401 for an invalid token or 404 if the repository cannot be found on GitHub.com): make sure your GitHub token is valid and that the repository is correct
If you’re uploading to Sourcegraph.com or another Sourcegraph instance with
lsifEnforceAuth enabled, you must prove that you own the GitHub repository in order to upload LSIF data for it. To do so, authenticate your upload by passing a GitHub App installation access token or a GitHub access token with
public_repo scope as
-github-token=abc.... You can create one at https://github.com/settings/tokens.
Make sure you have enabled LSIF code intelligence on your Sourcegraph instance.
Once the LSIF data is uploaded, navigate to a code file for the targeted language in the repository, or repository sub-directory LSIF was generated from. LSIF data should now be the source of hover-tooltips, definitions, and references for that file (presuming that LSIF data exists for that file).
To verify that code intelligence is coming from LSIF:
Now that you’re happy with the code intelligence on your repository, you need to make sure that is stays up to date with your repository. This can be done by periodically generating LSIF data, and pushing it to Sourcegraph. You can either add a step to your CI, or run it as a GitHub Action.