Sourcegraph

Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated
On self-managed GitLab, by default this feature is available. To hide the feature, an administrator can disable the feature flag named 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

Tier: Free, Premium, Ultimate Offering: Self-managed, GitLab Dedicated

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:

  1. Go to the Site admin area.
  2. Optional. Configure your GitLab external service. If your GitLab repositories are already searchable in Sourcegraph, you can skip this step.
  3. Confirm that you can search your repositories from GitLab in your Sourcegraph instance by running a test query.
  4. 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.
  1. On the left sidebar, at the bottom, select Admin.
  2. Select Settings > General.
  3. Expand Sourcegraph.
  4. Select Enable Sourcegraph.
  5. Optional. Select Block on private and internal projects.
  6. Set the Sourcegraph URL to your Sourcegraph instance, such as https://sourcegraph.example.com.
  7. 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:

  1. On the left sidebar, select your avatar.
  2. Select Preferences.
  3. Scroll to the Integrations section. Under Sourcegraph, select Enable integrated code intelligence on code views.
  4. Select Save changes.

References

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.