Code Suggestions (Beta) (FREE ALL)

WARNING: This feature is in Beta. Beta users should read about the known limitations. We look forward to hearing your feedback.

Write code more efficiently by using generative AI to suggest code while you're developing.

Code Suggestions are available:

  • To users of GitLab SaaS (by default) and self-managed GitLab Enterprise Edition (when requested). Code Suggestions are not available for GitLab Community Edition.
  • In VS Code, Microsoft Visual Studio, JetBrains IDEs, and Neovim. You must have the corresponding GitLab extension installed.
  • In the GitLab WebIDE.

Usage of Code Suggestions is governed by the GitLab Testing Agreement. Learn about data usage when using Code Suggestions.

Supported languages

The best results from Code Suggestions are expected for languages the Google Vertex AI Codey APIs directly support:

  • C++
  • C#
  • Go
  • Google SQL
  • Java
  • JavaScript
  • Kotlin
  • PHP
  • Python
  • Ruby
  • Rust
  • Scala
  • Swift
  • TypeScript

Supported code infrastructure interfaces

Code Suggestions includes Google Vertex AI Codey APIs support for the following infrastructure as code interfaces:

  • Google Cloud CLI
  • Kubernetes Resource Model (KRM)
  • Terraform

Suggestion quality for other languages and using natural language code comments to request completions may not yet result in high-quality suggestions.

Supported languages in IDEs

Editor support for languages is documented in the following table.

Language VS Code JetBrains IDEs Visual Studio Neovim
C++
C#
Go ✓ (IDEA Ultimate / GoLand)
Google SQL
Java
JavaScript
Kotlin
PHP ✓ (IDEA Ultimate)
Python
Ruby ✓ (IDEA Ultimate / RubyMine)
Rust
Scala
Swift
TypeScript
Google Cloud CLI
Kubernetes Resource Model (KRM)
Terraform ✓ (Requires 3rd party extension providing Terraform support)

Supported editor extensions

Code Suggestions supports a variety of popular editors including:

A GitLab Language Server for Code Suggestions is also in process. This improvement should result in:

  • Faster iteration and standardization of the IDE extensions.
  • The ability to use Code Suggestions even when an official editor extension isn't available.

Enable Code Suggestions on GitLab SaaS (FREE SAAS)

Code Suggestions can be enabled for all members of a group.

Each individual user must also choose to enable Code Suggestions.

Enable Code Suggestions for an individual user

Introduced in GitLab 16.1 as Beta.

Each user can enable Code Suggestions for themselves:

  1. On the left sidebar, select your avatar.
  2. Select Preferences.
  3. In the Code Suggestions section, select the Enable Code Suggestions checkbox.
  4. Select Save changes.

If Code Suggestions is enabled for the group, the group setting overrides the user setting.

NOTE: This setting controls Code Suggestions for all IDEs. Support for more granular control per IDE is proposed.

Enable Code Suggestions on self-managed GitLab (FREE SELF)

Introduced in GitLab 16.1 as Beta.

To enable Code Suggestions on a self-managed GitLab EE instance, you must:

  • Be an administrator.
  • Have a GitLab SaaS account. You do not need to have a GitLab SaaS subscription.

Then, you will:

  1. Enable Code Suggestions for your SaaS account.
  2. Enable Code Suggestions for the instance.
  3. Request early access to the Code Suggestions Beta.

Enable Code Suggestions for your SaaS account

To enable Code Suggestions for your GitLab SaaS account:

  1. Create a personal access token with the api scope.
  2. On the left sidebar, select your avatar.
  3. Select Preferences.
  4. In the Code Suggestions section, select Enable Code Suggestions.
  5. Select Save changes.

Enable Code Suggestions for the instance

You must enable Code Suggestions for the instance. When you do this, you:

  • Agree to the GitLab testing agreement.
  • Acknowledge that GitLab:
    • Sends data from the instance, including personal data, to GitLab.com infrastructure.

To enable Code Suggestions for your self-managed GitLab instance:

  1. On the left sidebar, expand the top-most chevron ({chevron-down}).
  2. Select Admin Area.
  3. On the left sidebar, select Settings > General.
  4. Expand Code Suggestions and:
    • Select Turn on Code Suggestions for this instance.
    • In Personal access token, enter your GitLab SaaS personal access token.
  5. Select Save changes.

This setting is visible only in self-managed GitLab instances.

WARNING: If you clear the Turn on code suggestions for this instance checkbox, the users in your instance can still use Code Suggestions for up to one hour, until the issued JSON web token (JWT) expires.

Request access to Code Suggestions

GitLab provisions access on a customer-by-customer basis for Code Suggestions on self-managed instances. To request access:

  1. Sign into your GitLab SaaS account.
  2. Comment on issue 415393 and tag your customer success manager.

After GitLab has provisioned access to Code Suggestions for your instance, the users in your instance can now enable Code Suggestions.

Use Code Suggestions

Prerequisites:

  1. Author your code. As you type, suggestions are displayed. Depending on the cursor position, the extension either:

    • Provides entire code snippets, like generating functions.
    • Completes the current line.
  2. To accept a suggestion, press Tab.

Suggestions are best when writing new code. Editing existing functions or 'fill in the middle' of a function may not perform as expected.

GitLab is making improvements to the Code Suggestions to improve the quality. AI is non-deterministic, so you may not get the same suggestion every time with the same input.

This feature is currently in Beta. Code Suggestions depends on both Google Vertex AI Codey APIs and the GitLab Code Suggestions service. We have built this feature to gracefully degrade and have controls in place to allow us to mitigate abuse or misuse. GitLab may disable this feature for any or all customers at any time at our discretion.

Code Suggestions data usage

Code Suggestions is a generative artificial intelligence (AI) model.

Your personal access token enables a secure API connection to GitLab.com. This API connection securely transmits a context window from your IDE/editor to the Code Suggestions GitLab hosted service which calls Google Vertex AI Codey APIs, and the generated suggestion is transmitted back to your IDE/editor.

GitLab currently leverages Google Cloud's Vertex AI Codey API models.

Data privacy

No new additional data is collected to enable this feature. Private non-public GitLab customer data is not used as training data.

Learn more about Google Vertex AI Codey APIs Data Governance

Inference window context

Code Suggestions currently inferences against the currently opened file and has a context window of 2,048 tokens and 8,192 character limits. This limit includes content before and after the cursor, the file name, and the extension type. Learn more about Google Vertex AI code-gecko.

The maximum number of tokens that is generated in the response is default 64. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. Learn more about Google Vertex AI code-gecko.

Self-managed instance data privacy

A self-managed GitLab instance does not generate the code suggestion. After successful authentication to the self-managed instance, a token is generated.

The IDE/editor then uses this token to securely transmit data directly to GitLab.com's Code Suggestions service for processing.

The Code Suggestion service then securely returns an AI-generated code suggestion.

Neither GitLab nor Google Vertex AI Codey APIs have any visibility into a self-managed customer's code other than what is sent to generate the code suggestion.

Training data

Code suggestions are routed through Google Vertex AI Codey APIs. Learn more about Google Vertex AI Codey APIs Data Governance and Responsible AI.

Google Vertex AI Codey APIs are not trained on private non-public GitLab customer or user data.

Google has shared the following about the data Codey models are trained on:

Codey is our family of foundational coding models built on PaLM 2. Codey was fine-tuned on a large dataset of high quality, permissively licensed code from external sources

Progressive enhancement

This feature is designed as a progressive enhancement to developer's IDEs. Code Suggestions offer a completion if the machine learning engine can generate a recommendation. In the event of a connection issue or model inference failure, the feature gracefully degrades. Code Suggestions do not prevent you from writing code in your IDE.

Internet connectivity

Code Suggestions does not work with offline environments.

To use Code Suggestions:

  • On GitLab.com, you must have an internet connection and be able to access GitLab.
  • In GitLab 16.1 and later, on self-managed GitLab, you must have an internet connection.

Model accuracy and quality

Code Suggestions can generate low-quality, incomplete, and possibly insecure code. We strongly encourage all beta users to leverage GitLab native Code Quality Scanning and Security Scanning capabilities.

GitLab currently does not retrain Google Vertex AI Codey APIs. GitLab makes no claims to the accuracy or quality of code suggestions generated by Google Vertex AI Codey API. Read more about Google Vertex AI foundation model capabilities.

Known limitations

While in Beta, we are working on improving the accuracy of overall generated content. However, Code Suggestions may generate suggestions that are:

  • Low-quality
  • Incomplete
  • Produce failed pipelines
  • Insecure code
  • Offensive or insensitive

We are also aware of specific situations that can produce unexpected or incoherent results including:

  • Suggestions written in the middle of existing functions, or "fill in the middle."
  • Suggestions based on natural language code comments.
  • Suggestions that mixed programming languages in unexpected ways.

Feedback

Report issues in the feedback issue.

Troubleshooting

Code Suggestions aren't displayed

If Code Suggestions are not displayed, try the following troubleshooting steps.

In GitLab, ensure Code Suggestions is enabled:

To confirm that your account is enabled, go to https://gitlab.com/api/v4/ml/ai-assist. A response of user_is_allowed should return true.

Code Suggestions not displayed in VS Code or GitLab WebIDE

Check all the steps in Code Suggestions aren't displayed first.

If you are a self-managed user, ensure that Code Suggestions for the GitLab WebIDE are enabled. The same settings apply to VS Code as local IDE.

  1. On the left sidebar, select Extensions > GitLab Workflow.
  2. Select Settings ({settings}), and then select Extension Settings.
  3. In GitLab > AI Assisted Code Suggestions, select the Enable code completion (Beta) checkbox.

If the settings are enabled, but Code Suggestions are still not displayed, try the following steps:

  1. Enable the Debug checkbox in the GitLab Workflow Extension Settings.
  2. Open the extension log in View > Output and change the dropdown list to GitLab Workflow as the log filter. The command palette command is GitLab: Show Extension Logs.
  3. Disable and re-enable the Enable code completion (Beta) checkbox.
  4. Verify that the debug log contains similar output:
2023-07-14T17:29:00:763 [debug]: Disabling code completion
2023-07-14T17:29:01:802 [debug]: Enabling code completion
2023-07-14T17:29:01:802 [debug]: AI Assist: Using server: https://codesuggestions.gitlab.com/v2/completions

Code Suggestions not displayed in Microsoft Visual Studio

Check all the steps in Code Suggestions aren't displayed first.

  1. Ensure you have properly set up the extension.
  2. From the Tools > Options menu, find the GitLab option. Ensure Log Level is set to Debug.
  3. Open the extension log in View > Output and change the dropdown list to GitLab Extension as the log filter.
  4. Verify that the debug log contains similar output:
14:48:21:344 GitlabProposalSource.GetCodeSuggestionAsync
14:48:21:344 LsClient.SendTextDocumentCompletionAsync("GitLab.Extension.Test\TestData.cs", 34, 0)
14:48:21:346 LS(55096): time="2023-07-17T14:48:21-05:00" level=info msg="update context"

Authentication troubleshooting

If the above steps do not solve your issue, the problem may be related to the recent changes in authentication, specifically the token system. To resolve the issue:

  1. Remove the existing personal access token from your GitLab account settings.
  2. Reauthorize your GitLab account in VS Code using OAuth.
  3. Test the code suggestions feature with different file extensions to verify if the issue is resolved.