- Set up for self-managed GitLab instances
- Enable Sourcegraph in user preferences
- References
- Troubleshooting
Sourcegraph
sourcegraph
.
On GitLab.com, this feature is available for public projects only.Sourcegraph provides code intelligence features in the GitLab UI. When enabled, participating projects display a code intelligence popover in these code views:
- Merge request diffs
- Commit view
- File view
When visiting one of these views, hover over a code reference to see a popover with:
- Details on how this reference was defined.
- Go to definition, which goes to the line of code where this reference was defined.
- Find references, which goes to the configured Sourcegraph instance, showing a list of references to the highlighted code.
For an overview, watch the video Sourcegraph’s new GitLab native integration.
For more information, see epic 2201.
Set up for self-managed GitLab instances
Prerequisites:
- You must have a Sourcegraph instance configured and running with your GitLab instance as an external service.
- If your Sourcegraph instance uses a HTTPS connection to GitLab, you must configure HTTPS for your Sourcegraph instance.
In Sourcegraph:
- Go to the Site admin area.
- Optional. Configure your GitLab external service. If your GitLab repositories are already searchable in Sourcegraph, you can skip this step.
- Confirm 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 Sourcegraph configuration.
Next, configure your GitLab instance to connect to your Sourcegraph instance.
Configure your GitLab instance with Sourcegraph
Prerequisites:
- You must be an administrator.
- On the left sidebar, at the bottom, select Admin.
- Select Settings > General.
- Expand Sourcegraph.
- Select Enable Sourcegraph.
- Optional. Select Block on private and internal projects.
- Set the Sourcegraph URL to your Sourcegraph instance, such as
https://sourcegraph.example.com
. - Select Save changes.
Enable Sourcegraph in user preferences
Users on self-managed instances must also configure their user settings to use the Sourcegraph integration.
On GitLab.com, the integration is available for all public projects. Private projects are not supported.
Prerequisites:
- If on a self-managed instance, Sourcegraph must be enabled.
To enable this feature in your GitLab user preferences:
- On the left sidebar, select your avatar.
- Select Preferences.
- Scroll to the Integrations section. Under Sourcegraph, select Enable integrated code intelligence on code views.
- Select Save changes.
References
- Privacy information in the Sourcegraph documentation
Troubleshooting
Sourcegraph is not working
If you enabled Sourcegraph for your project but it is not working, Sourcegraph might 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.