Sourcegraph (FREE)
- Introduced in GitLab 12.5 with a flag named
sourcegraph
. Disabled by default.- Enabled on GitLab.com in GitLab 12.5.
- Enabled on self-managed in GitLab 14.8.
FLAG:
On self-managed GitLab, by default this feature is available. To hide the feature, ask an administrator to disable the feature flag named sourcegraph
.
On GitLab.com, this feature is available for public projects only.
Sourcegraph provides code intelligence features, natively integrated into the GitLab UI.
For GitLab.com users, see Sourcegraph for GitLab.com.
For an overview, watch the video Sourcegraph's new GitLab native integration.
NOTE: This feature requires user opt-in. After Sourcegraph has been enabled for your GitLab instance, you can choose to enable Sourcegraph through your user preferences.
Set up for self-managed GitLab instances (FREE SELF)
Before you can enable Sourcegraph code intelligence in GitLab you must: configure a Sourcegraph instance with your GitLab instance as an external service.
Set up a self-managed Sourcegraph instance (FREE SELF)
If you are new to Sourcegraph, head over to the Sourcegraph installation documentation and get your instance up and running.
If you are using an HTTPS connection to GitLab, you must configure HTTPS for your Sourcegraph instance.
Connect your Sourcegraph instance to your GitLab instance
- Navigate to the site Admin Area in Sourcegraph.
- Configure your GitLab external service. You can skip this step if you already have your GitLab repositories searchable in Sourcegraph.
- Validate that you can search your repositories from GitLab in your Sourcegraph instance by running a test query.
- Add your GitLab instance URL to the
corsOrigin
setting in your site configuration.
Configure your GitLab instance with Sourcegraph
- On the top bar, select Main menu > Admin.
- On the left sidebar, select Settings > General.
- Expand the Sourcegraph configuration section.
- Check Enable Sourcegraph.
- Set the Sourcegraph URL to your Sourcegraph instance, such as
https://sourcegraph.example.com
.
Enable Sourcegraph in user preferences
If a GitLab administrator has enabled Sourcegraph, you can enable this feature in your user preferences.
In GitLab:
- In the upper-right corner, select your avatar.
- Select Preferences.
- In the Integrations section, select the checkbox under Sourcegraph.
- Select Save changes.
Using Sourcegraph code intelligence
Once enabled, participating projects display a code intelligence popover available in the following code views:
- Merge request diffs
- Commit view
- File view
When visiting one of these views, you can now hover over a code reference to see a popover with:
- Details on how this reference was defined.
- Go to definition, which navigates to the line of code where this reference was defined.
- Find references, which navigates to the configured Sourcegraph instance, showing a list of references to the highlighted code.
Sourcegraph for GitLab.com
Sourcegraph is available for all public projects on GitLab.com. Private projects are not supported. For more information, see epic 2201.
Sourcegraph and privacy
See the Sourcegraph browser extension documentation.
Troubleshooting
Sourcegraph isn't working
If you enabled Sourcegraph for your project but it isn't working, Sourcegraph may not have indexed the project yet. You can check if Sourcegraph is available for your project by visiting https://sourcegraph.com/gitlab.com/<project-path>
replacing <project-path>
with the path to your GitLab project.