Sourcegraph

Tier:Free, Premium, Ultimate Offering:GitLab, Self-managed, GitLab Dedicated
On self-managed GitLab, by default this feature is available. To hide the feature, an administrator candisable the feature flagnamedsourcegraph. On GitLab, this feature is available for public projects only.

Sourcegraphprovides 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 videoSourcegraph’s new GitLab native integration.

For more information, seeepic 2201.

Set up for self-managed GitLab instances

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

Prerequisites:

  • You must have a Sourcegraph instanceconfigured 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 theSite adminarea.
  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 thecorsOriginsetting 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, selectAdmin.
  2. SelectSettings > General.
  3. ExpandSourcegraph.
  4. SelectEnable Sourcegraph.
  5. Optional. SelectBlock on private and internal projects.
  6. Set theSourcegraph URLto your Sourcegraph instance, such ashttps://sourcegraph.example.
  7. SelectSave changes.

Enable Sourcegraph in user preferences

Users on self-managed instances must also configure their user settings to use the Sourcegraph integration.

On GitLab, 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. SelectPreferences.
  3. Scroll to theIntegrationssection. UnderSourcegraph,selectEnable integrated code intelligence on code views.
  4. SelectSave 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 visitinghttps://sourcegraph /gitlab /<project-path>,replacing<project-path> with the path to your GitLab project.