Code Suggestions

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

Model information

Version history

  • Introduced support for Google Vertex AI Codey APIs in GitLab 16.1.
  • Removed support for GitLab native model in GitLab 16.2.
  • Introduced support for code generation in GitLab 16.3.
  • Generally available in GitLab 16.7.
  • Changed to require the GitLab Duo Pro add-on on February 15, 2024. Previously, this feature was included with Premium and Ultimate subscriptions.
  • Changed to require the GitLab Duo Pro or GitLab Duo Enterprise add-on for all supported GitLab versions starting October 17, 2024.
  • Introduced support for Fireworks AI-hosted Qwen2.5 code completion model in GitLab 17.6, with a flag named fireworks_qwen_code_completion.
  • Removed support for Qwen2.5 code completion model in GitLab 17.11.
  • Enabled Fireworks hosted Codestral by default via the feature flag use_fireworks_codestral_code_completion in GitLab 17.11.
  • Changed to include GitLab Duo Core in GitLab 18.0.
  • Enabled Fireworks hosted Codestral as the default model in GitLab 18.1.
  • Changed the default model for code generation to Claude Sonnet 4 in GitLab 18.2.
  • Removed feature flag code_suggestions_context in GitLab 18.6.
  • Available on the Free tier on GitLab.com with GitLab Credits in GitLab 18.10.
  • Changed GitLab Duo Core user access to Code Suggestions. Now available as part of the GitLab Duo Agent Platform starting in GitLab 19.0.

Note

Code Suggestions is available for:

  • GitLab Duo Agent Platform. Billing is usage-based.
  • GitLab Duo Pro or Enterprise, GitLab Duo with Amazon Q. Billing is based on your add-on.

Use GitLab Duo Code Suggestions to write code more efficiently by using generative AI to suggest code while you're developing.

Prerequisites

Note

GitLab Duo requires GitLab 17.2 or later. For GitLab Duo Core access, and for the best user experience and results, upgrade to GitLab 18.0 or later. Earlier versions might continue to work, however the experience might be degraded.

Use Code Suggestions

To use Code Suggestions:

  1. Open a project in your IDE. The local project must have a Git remote configured that points to a repository on GitLab.

  2. Author your code. As you type, suggestions are displayed. Code Suggestions provides code snippets or completes the current line, depending on the cursor position.

  3. Describe the requirements in natural language. Code Suggestions generates functions and code snippets based on the context provided.

  4. When you receive a suggestion, you can do any of the following:

    • To accept a suggestion, press Tab.
    • To accept a partial suggestion, press either Control+Right arrow or Command+Right arrow.
    • To reject a suggestion, press Esc. In Neovim, press Control+E to exit the menu.
    • To ignore a suggestion, keep typing as you usually would.

View multiple code suggestions

Version history

For a code completion suggestion in VS Code, multiple suggestion options might be available. To view all available suggestions:

  1. Hover over the code completion suggestion.
  2. Scroll through the alternatives. Either:
    • Use keyboard shortcuts:
      • On a Mac, press Option+[ to view the previous suggestion, and press Option+] to view the next suggestion.
      • On Linux and Windows, press Alt+[ to view the previous suggestion, and press Alt+] to view the next suggestion.
    • On the dialog that's displayed, select the right or left arrow to see next or previous options.
  3. Press Tab to apply the suggestion you prefer.

Code completion and generation

Code Suggestions uses code completion and code generation:

Code completion Code generation
Purpose Provides suggestions for completing the current line of code. Generates new code based on a natural language comment.
Trigger Triggers when typing, usually with a short delay. Triggers when pressing Enter after writing a comment that includes specific keywords.
Scope Limited to the current line or small block of code. Can generate entire methods, functions, or even classes based on the context.
Accuracy More accurate for small tasks and short blocks of code. Is more accurate for complex tasks and large blocks of code because a bigger large language model (LLM) is used, additional context is sent in the request (for example, the libraries used by the project), and your instructions are passed to the LLM.
How to use Code completion automatically suggests completions to the line you are typing. You write a comment and press Enter, or you enter an empty function or method.
When to use Use code completion to quickly complete one or a few lines of code. Use code generation for more complex tasks, larger codebases, when you want to write new code from scratch based on a natural language description, or when the file you're editing has fewer than five lines of code.

Code Suggestions always uses both of these features. You cannot use only code generation or only code completion.

View a code completion vs. code generation comparison demo.

Best practices for code generation

To get the best results from code generation:

  • Be as specific as possible while remaining concise.
  • State the outcome you want to generate (for example, a function) and provide details on what you want to achieve.
  • Add additional information, like the framework or library you want to use.
  • Add a space or new line after each comment. This space tells the code generator that you have completed your instructions.
  • Review and adjust the context available to Code Suggestions.

For example, to create a Python web service with some specific requirements, you might write something like:

# Create a web service using Tornado that allows a user to sign in, run a security scan, and review the scan results.
# Each action (sign in, run a scan, and review results) should be its own resource in the web service
...

AI is non-deterministic, so you may not get the same suggestion every time with the same input. To generate quality code, write clear, descriptive, specific tasks.

For use cases and best practices, follow the GitLab Duo examples documentation.

Available language models

Different language models can be the source for Code Suggestions.

Accuracy of results

We are continuing to work on the accuracy of overall generated content. However, Code Suggestions might generate suggestions that are:

  • Irrelevant.
  • Incomplete.
  • Likely to result in failed pipelines.
  • Potentially insecure.
  • Offensive or insensitive.

When using Code Suggestions, code review best practices still apply.