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:
- Generate code for your project with code transformation.
- Receive code completions while you're coding.
- Use smart actions.
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. Learn how 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 in Cloud Shell Editor, Cloud Workstations, and Android Studio.
Before you begin
VS Code
Set up Gemini Code Assist Standard or Enterprise, if you haven't already.
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, see Supported coding languages.
If you prefer to use your IDE behind a proxy, see Network Connections in Visual Studio Code.
IntelliJ
Set up Gemini Code Assist Standard or Enterprise, if you haven't already.
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, see Supported coding languages.
If you prefer to use your IDE behind a proxy, see HTTP 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
In your code file, on a new line, press Control+I (for Windows and Linux) or Command+I (for macOS) to open the Gemini Code Assist Quick Pick menu.
In the menu, using the
/generatecommand, enter/generate function to create a Cloud Storage bucketand then press Enter (for Windows and Linux) or Return (for macOS).
Gemini Code Assist generates the code based on your prompt in a diff view.
Optional: To accept these changes, click Accept.
IntelliJ
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.
In the menu, using the
/generatecommand, enter/generate function to create a Cloud Storage bucketand then press Enter (for Windows and Linux) or Return (for macOS).
Gemini Code Assist generates the code based on your prompt in a diff view.
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.
Prompt Gemini Code Assist in a code file with a comment
If you prefer, you can also prompt Gemini Code Assist in your code file with a comment by following these steps:
VS Code
On a new line, enter the comment
Function to create a Cloud Storage bucket, and then press Enter (for Windows and Linux) or Return (for macOS).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.
Optional: To accept the generated code, press Tab.
IntelliJ
In your code file, on a new line, enter the comment
Function to create a Cloud Storage bucket.To generate code, press Alt+G (for Windows and Linux) or Option+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.
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 can change 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
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.
To accept the code suggestion from Gemini Code Assist, press Tab. Otherwise, to ignore the suggestion, press Esc or continue writing your code.
IntelliJ
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.
To accept the code suggestion from Gemini Code Assist, press Tab. Otherwise, to ignore the suggestion, press Esc or continue writing your code.
Optional: If you prefer to use a different shortcut key to accept the inline suggestion, hold your pointer over the inline suggestion and click the Tab dropdown that appears. Then, select your preferred shortcut or click Custom to enter your own shortcut.
Optional: Disable code completion
Code completion is enabled by default. If you want to disable code completion, follow these steps:
VS Code
In your IDE, click Code (for macOS) or File (for Windows and Linux), and then navigate to Preferences > Settings.
On the User tab of the Settings dialog, navigate to Extensions > Gemini Code Assist.
Scroll until you find the Geminicodeassist > Inline Suggestions: Enable Auto list, and then select Off.
This turns off the inline suggestions. You can still press Control+Enter (for Windows and Linux) or Control+Return (for macOS) to manually trigger inline suggestions.
IntelliJ
In the status bar of your IDE, click spark Gemini Code Assist: Active and select Enable AI Code Completion.
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:
Navigate to settings Manage > Settings.
In the User tab of the settings window, navigate to Extensions > Gemini Code Assist.
Scroll until you find Geminicodeassist > Inline Suggestions: Next Edit Predictions.
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:
In your code file, start writing code. Next Edit Predictions appear when you pause or stop typing.
Press Tab to accept the provided Next Edit suggestion.
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.
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:
Navigate to File > Settings > Tools > Gemini.
In the Completion section, select the Next Edit Predictions checkbox 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:
In your code file, start writing code. Next Edit Predictions appear when you pause or stop typing.
Press Tab to accept the provided Next Edit suggestion.
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
In your code file, start writing code until the
Alt+For