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