Code with Gemini Code Assist Standard and Enterprise (original) (raw)

This document describes how you can use Gemini Code Assist, an AI-powered collaborator in your IDE, to help you do the following in VS Code or IntelliJ and other supported JetBrains IDEs:

If you're using Gemini Code Assist Enterprise, you can use Code customization, which lets you get code suggestions based on your organization's private codebase directly from Gemini Code Assist Enterprise. Learnhow to configure code customization.

This document is intended for developers of all skill levels. It assumes you have working knowledge of VS Code or IntelliJ and other supported JetBrains IDEs, and are familiar with Google Cloud. If you prefer, you can also explore Gemini Code Assist inCloud Shell Editor,Cloud Workstations, and Android Studio.

Before you begin

VS Code

  1. Set up Gemini Code Assist Standard or Enterprise, if you haven't already.
  2. Before testing Gemini Code Assist capabilities in your code file, make sure your file's coding language is supported. For more information on supported coding languages, seeSupported coding languages.
  3. If you prefer to use your IDE behind a proxy, seeNetwork Connections in Visual Studio Code.

IntelliJ

  1. Set up Gemini Code Assist Standard or Enterprise, if you haven't already.
  2. Before testing Gemini Code Assist capabilities in your code file, make sure your file's coding language is supported. For more information on supported coding languages, seeSupported coding languages.
  3. If you prefer to use your IDE behind a proxy, seeHTTP Proxy.

Generate code with prompts

The following sections show you how to use Gemini Code Assist to generate code with the example prompt Function to create a Cloud Storage bucket inside your code file. You can also select a part of your code and then prompt Gemini Code Assist for help through the chat feature, and receive and accept or reject code suggestions while you code.

Prompt Gemini Code Assist with code transformation

Code transformation allows you to use commands or natural language prompts in the Quick Pick menu to request modifications to your code, and provides you with a diff view to show pending changes to your code. To prompt Gemini Code Assist with code transformation, follow these steps:

VS Code

  1. In your code file, on a new line, press Control+I (for Windows and Linux) or Command+I (for macOS) to open theGemini Code Assist Quick Pick menu.
  2. In the menu, using the /generate command, enter /generate function to create a Cloud Storage bucket and then press Enter (for Windows and Linux) or Return (for macOS).
    Gemini Code Assist generates code with the /generate command.
    Gemini Code Assist generates the code based on your prompt in a diff view.
    Gemini Code Assist opens a diff view to show generated code.
  3. Optional: To accept these changes, click Accept.

IntelliJ

  1. In your code file, on a new line, press Alt+\ (for Windows and Linux) or Cmd+\ (for macOS) to open the Gemini Code Assist Quick Pick menu.
  2. In the menu, using the /generate command, enter /generate function to create a Cloud Storage bucket and then press Enter (for Windows and Linux) or Return (for macOS).
    Code transformation generate function in IntelliJ Gemini Code Assist
    Gemini Code Assist generates the code based on your prompt in a diff view.
    Code transformation diff view in IntelliJ Gemini Code Assist
  3. Optional: To accept these changes, click Accept Changes.
    You can use the following code transformation commands in your IDE:
    • /fix: Fix issues or errors in your code. Example: /fix potential NullPointerExceptions in my code.
    • /generate: Generate code. Example: /generate a function to get the current time.
    • /doc: Add documentation to your code. Example: /doc this function.
    • /simplify: Simplify your code. Example: /simplify if statement in this code.

If you prefer, you can also prompt Gemini Code Assist in your code file with a comment by following these steps:

VS Code

  1. On a new line, enter the comment Function to create a Cloud Storage bucket, and then press Enter (for Windows and Linux) orReturn (for macOS).
  2. To generate code, press Control+Enter (for Windows and Linux) or Control+Return (for macOS).
    Next to your prompt text in your code file, Gemini Code Assist generates the code in the form of ghost text.
  3. Optional: To accept the generated code, press Tab.

IntelliJ

  1. In your code file, on a new line, enter the comment Function to create a Cloud Storage bucket.
  2. To generate code, press Alt+G (for Windows and Linux) orOption+G (for macOS). Alternatively, you can right-click next to the comment and select Generate Code.
    Gemini Code Assist generates the code below your comment in the form of ghost text.
  3. Optional: To accept the generated code, press Tab.

Optional: Change keyboard shortcut for generating code

If the default keyboard shortcut for generating code isn't working as outlined in the previous section, you canchange the keyboard shortcut.

Get code completions

While you write code, Gemini Code Assist makes inline code suggestions, also known as code completions, that you can either accept or ignore. To get code completions, follow these steps:

VS Code

  1. In your code file, on a new line, start writing a function. For example, if you're in a Python file, write def.
    Gemini Code Assist suggests code in the form of ghost text.
  2. To accept the code suggestion from Gemini Code Assist, press Tab. Otherwise, to ignore the suggestion, pressEsc or continue writing your code.

IntelliJ

  1. In your code file, on a new line, start writing a function. For example, if you're in a Python file, write def.
    Gemini Code Assist suggests code in the form of an inline suggestion.
  2. To accept the code suggestion from Gemini Code Assist, press Tab. Otherwise, to ignore the suggestion, pressEsc or continue writing your code.
  3. Optional: If you prefer to use a different shortcut key to accept the inline suggestion, hold your pointer over the inline suggestion and click theTab dropdown that appears. Then, select your preferred shortcut or clickCustom to enter your own shortcut.
    Gemini provides a dropdown menu to change your shortcut to accept an inline suggestion.

Optional: Disable code completion

Code completion is enabled by default. If you want to disable code completion, follow these steps:

VS Code

  1. In your IDE, click Code (for macOS) or File (for Windows and Linux), and then navigate to Preferences > Settings.
  2. On the User tab of the Settings dialog, navigate to Extensions > Gemini Code Assist.
  3. Scroll until you find the Geminicodeassist > Inline Suggestions: Enable Autolist, and then select Off.
    This turns off the inline suggestions. You can still pressControl+Enter (for Windows and Linux) orControl+Return (for macOS) to manually trigger inline suggestions.

IntelliJ

In the status bar of your IDE, clickspark Gemini Code Assist: Active and select Enable AI Code Completion.

Gemini Code Completion button in IntelliJ status bar.

This disables the code completion setting, and Gemini Code Assist no longer makes inline suggestions until you enable the setting again.

Use Next Edit Predictions

While code completion only suggests changes at your cursor in a code file, Next Edit Predictions provide predicted code suggestions throughout the file, even in locations away from the cursor.

You can enable Next Edit Predictions in the settings of your IDE.

To use Next Edit Predictions in your IDE, follow these steps:

VS Code

To begin using Next Edit Predictions, enable the setting:

  1. Navigate to settings Manage > Settings.
  2. In the User tab of the settings window, navigate to Extensions > Gemini Code Assist.
  3. Scroll until you find Geminicodeassist > Inline Suggestions: Next Edit Predictions.
  4. Select the checkbox to enable Next Edit Predictions in VS Code.

Now that you've enabled the setting, you can start using Next Edit Predictions in a code file by performing these steps:

  1. In your code file, start writing code. Next Edit Predictions appear when you pause or stop typing.
    User triggers the Next Edit Predictions in VS Code Gemini Code Assist.
  2. Press Tab to accept the provided Next Edit suggestion.
    User enters the Next Edit Prediction in VS Code Gemini Code Assist.
  3. If you want to accept the next suggestion, press Tab again. A further suggestion may appear and the process can again be repeated. Otherwise, press Esc to dismiss, or continue typing to ignore the suggestion.
    When you press Tab to enter the suggestion, you can hold your pointer over the suggestion to see the other suggestions, if applicable. If there are multiple suggestions, you can click the left and right arrows to cycle through the other suggestions.
    Available Next Edit Predictions in VS Code Gemini Code Assist.
    Whenever you press Esc to dismiss the suggestion, Gemini Code Assist stops suggesting Next Edit Predictions for that specific code block. You continue to receive suggestions when you move to another section of your code.

IntelliJ

To begin using Next Edit Predictions, enable the setting:

  1. Navigate to File > Settings > Tools > Gemini.
  2. In the Completion section, select the Next Edit Predictionscheckbox to enable the feature.

Now that you've enabled the setting, you can start using Next Edit Predictions in a code file by performing these steps:

  1. In your code file, start writing code. Next Edit Predictions appear when you pause or stop typing.
    User triggers the Next Edit Predictions in IntelliJ Gemini Code Assist.
  2. Press Tab to accept the provided Next Edit suggestion.
    User enters the Next Edit Prediction in IntelliJ Gemini Code Assist.
  3. If you want to accept the next suggestion, press Tab again. A further suggestion may appear and the process can again be repeated. Otherwise, press Esc to dismiss, or continue typing to ignore the suggestion.
    Whenever you press Esc to dismiss the suggestion, Gemini Code Assist stops suggesting Next Edit Predictions for that specific code block. You continue to receive suggestions when you move to another section of your code.

Finish changes in a file

Gemini Code Assist can generate code suggestion to complete your file's pseudocode, #TODOs, and half-written code.

VS Code

This feature isn't supported in Gemini Code Assist for VS Code.

IntelliJ

  1. Check that there are portions of your focused file that have code in need of completion, such as pseudocode or #TODOs.
  2. In the file window, right-click > Gemini > Finish changes. Alternatively, you canuse the finish changes keyboard shortcut.
    Gemini Code Assist generates code suggestions to finish the incomplete portions of your code.
  3. For each code suggestion, click check_small Accept orundo Reject.
    Alternatively, the option to Accept all or Reject all is available at the top of the file.

Get more relevant suggestions with remote repository context

You can get more contextually aware and relevant code suggestions by directing Gemini Code Assist to focus on specific remote repositories. This is useful when your task centers on a specific set of microservices, libraries, or modules.

Before you begin

Before you use a remote repository as context, you must firstindex and configure it for code customization.

Use a remote repository as context

To direct Gemini Code Assist to use one or more repositories as the primary context for your prompts:

  1. In your IDE's chat, start your prompt with the @ symbol. A list of your available indexed remote repositories appears.
  2. Select the repository (or repositories) you want to use for context from the list. You can also start typing the repository name to filter the list.
  3. After selecting the repositories, write the rest of your prompt.

Gemini Code Assist then prioritizes the selected repositories when generating a response.

Example prompts

This section includes examples of how you can get more relevant suggestions with remote repository context.

By using remote repositories as a focused source of context, you can get more accurate and relevant suggestions from Gemini Code Assist, which can help you code faster and more efficiently.

Use smart actions

To help you be more productive while minimizing context switching, Gemini Code Assist provides AI-powered smart actions directly in your code editor. When you select your code in your code editor, you can view and select from a list of actions relevant to your context.

To use smart actions in your code, follow these steps:

VS Code

  1. In your code file, select a block of code.
  2. Next to the selected code block, clicklightbulb Show Code Actions.
    Smart actions lightbulb icon appears after selecting a block of code in VS Code.
  3. Select an action such as Generate unit tests.
    Gemini Code Assist generates a response that's based on the action you selected.

IntelliJ

  1. In your code file, select a line or block of code.
  2. Right-click the selected code and select a smart action, likeGenerate unit tests.
    Selecting the smart action will automatically prompt Gemini Code Assist to generate a response to the prompt in the Gemini Code Assist tool window.

Use code transformation quick fix

If there's an error in your code, Gemini Code Assist gives you the option to apply a quick fix to the error with code transformation.

To apply a quick fix in your code file, follow these steps:

VS Code

  1. In your code file, hold your pointer over the squiggly error line and select Quick Fix, and then select /fix.
    Code transformation quick fix in the IDE.
  2. When the quick fix is applied, a diff view appears. To accept these changes, click Accept.

IntelliJ

  1. In your code file, click the red error bulb icon, which indicates an error in your code, and select Fix with Gemini.
    Code transformation option to fix with Gemini in the IDE.
  2. When the fix is applied, a diff view appears. To accept these changes, click Accept.

Exclude files from local context

If files are specified in a .aiexclude or .gitignore file, Gemini Code Assist by default excludes them from local use in the context for code completion, code generation, code transformation, and chat.

To learn how to exclude files from local use, seeExclude files from Gemini Code Assist use.

Disable code suggestions that match cited sources

Gemini Code Assist provides citation information when it directly quotes at length from another source, such as existing open source code. For more information, seeHow and when Gemini cites sources.

To prevent code that matches cited sources from being suggested to you, do the following:

VS Code

  1. In the activity bar of your IDE, click Manage > Settings.
  2. In the User tab of the settings window, navigate to Extensions > Gemini Code Assist.
  3. Scroll until you find Geminicodeassist > Recitation: Max Cited Length.
  4. Set the value to 0.

Gemini Code Assist no longer suggests code to you that matches cited sources.

IntelliJ

  1. In the status bar of your IDE, clickspark Gemini Code Assist: Active and select then selectConfigure Gemini.
  2. Expand the Advanced settings section, and then selectBlock selections that match external cited sources.
  3. Click OK.

Gemini Code Assist no longer suggests code to you that matches cited sources.

Known issues

This section outlines the known issues of Gemini Code Assist:

VS Code

 "cloudcode.beta.forceOobLogin": true  
export GRPC_GO_LOG_SEVERITY_LEVEL=info  

IntelliJ

There are no known issues for Gemini Code Assist for IntelliJ and other supported JetBrains IDEs.

Leave feedback

To leave feedback of your experience, seeProvide Gemini for Google Cloud feedback.

What's next