Code intelligence
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
Code intelligence adds features common to interactive development environments (IDE), including:
- Type signatures and symbol documentation.
- Go-to definition.
Code intelligence is built into GitLab and powered by LSIF (Language Server Index Format), a file format for precomputed code intelligence data. GitLab processes one LSIF file per project, and Code intelligence does not support different LSIF files per branch.
SCIP is the next evolution of tooling for indexing source code. You can use it to power features, such as:
- Go to definition
- Find references
GitLab does not natively support SCIP for code intelligence. However, you can use the SCIP CLI to convert indexes generated with SCIP tooling into a LSIF-compatible file. For discussions on native SCIP support, see issue 412981.
For progress on upcoming code intelligence enhancements, see epic 4212.
GitLab also provides code navigation, which reads the knowledge graph that GitLab Orbit builds from your code instead of an LSIF file, so it doesn’t need an indexer or a CI/CD job.
Configure code intelligence
Prerequisites:
- You’ve checked to ensure there is a compatible indexer for your project’s languages:
To see how your language is best supported, review the indexers recommended by Sourcegraph.
With the CI/CD component
GitLab provides a CI/CD component to configure code intelligence
in your .gitlab-ci.yml file. The component supports these languages:
- Go version 1.21 or later.
- TypeScript or JavaScript.
- Java 8, 11, 17, and 21.
- Python
- .Net/C#
To contribute more languages to the component, open a merge request in the code intelligence component project.
Add a GitLab CI/CD component to your project’s
.gitlab-ci.yml. For example, this job generates the LSIF artifact for Go:include: - component: ${CI_SERVER_FQDN}/components/code-intelligence/[email protected] inputs: golang_version: ${GO_VERSION}For configuration instructions for the code intelligence component, check the
READMEfor each supported language.For more information, see use a component.
Add CI/CD jobs for code intelligence
To enable code intelligence for a project, add GitLab CI/CD jobs to your project’s .gitlab-ci.yml.
Add a job to your
.gitlab-ci.ymlconfiguration. This job generates the SCIP index and converts it to LSIF for use in GitLab:"code_navigation": rules: - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH # the job only needs to run against the default branch image: node:latest stage: test allow_failure: true # recommended script: - npm install -g @sourcegraph/scip-typescript - npm install - scip-typescript index - | env \ TAG="v0.4.0" \ OS="$(uname -s | tr '[:upper:]' '[:lower:]')" \ ARCH="$(uname -m | sed -e 's/x86_64/amd64/')" \ bash -c 'curl --location "https://github.com/sourcegraph/scip/releases/download/$TAG/scip-$OS-$ARCH.tar.gz"' \ | tar xzf - scip - chmod +x scip - ./scip convert --from index.scip --to dump.lsif artifacts: reports: lsif: dump.lsifDepending on your CI/CD configuration, you might need to run the job manually, or wait for it to run as part of an existing pipeline.
Add a job (
code_navigation) to your.gitlab-ci.ymlconfiguration to generate the index:code_navigation: