Provide guidance to help you solve problems with your code.
Generate code for your project.
Receive inline suggestions while you're coding.
Learn how and when Gemini for Google Cloud uses your data.
To help you comply with any license requirements for your code, Gemini Code Assist provides source citations when its suggestions directly quote at length from a specific source. To learn more about how and when Gemini cites sources, see How Gemini helps you generate code and cites sources.Code customization lets you get code suggestions based on your organization's private codebase directly from Gemini Code Assist. Learn how to configure code customization.
This document is intended for developers of all skill levels. It assumes you have working knowledge of IntelliJ and are familiar with Google Cloud. If you prefer, you can also explore Gemini Code Assist in Cloud Workstations, Cloud Code for VS Code, and Cloud Shell Editor.
Before you begin
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.
Install the Gemini Code Assist/Cloud Code extension if you haven't already. Gemini Code Assist and Cloud Code are bundled together.
If you prefer to use your IDE behind a proxy, see HTTP Proxy.
Install the Gemini Code Assist plugin
To install the Gemini Code Assist plugin in your JetBrains IDE, follow these steps:
- Click settings IDE and Project Settings > Plugins.
- In the Marketplace tab, search for
Gemini Code Assist/Cloud Code
. - Click Install to install the plugin.
- When the installation is finished, click Restart IDE.
When the IDE restarts, Gemini Code Assist appears in your activity bar.
Now you're ready to use Gemini Code Assist in your IDE.
Sign into Google and select a Google Cloud project
In this section, you sign in to your Google Account, and if it's your first time using Gemini Code Assist in your IDE, you select a Google Cloud project.
To sign in to your Google Account, follow these steps:
In the activity bar, click spark Gemini Code Assist.
Click Log in to Google.
On the page that opens in the web browser, select your Google Account.
On the screen that asks you to make sure that you downloaded this app from Google, click Sign in.
Gemini Code Assist is now authorized to access your account.
Next, if this is your first time using Gemini in your IDE, you must select a Google Cloud project by following these steps:
Return to your IDE. In the Gemini Code Assist tool window, if you agree to allow Google to enable the APIs required to use Gemini Code Assist on your behalf for your selected project, click Select a GCP project to continue.
In the Select Google Cloud Project dialog, search for and select your Google Cloud project, and then click OK.
Click FINISH.
Your Google Cloud project is selected with the Gemini Code Assist API enabled. You're ready to use Gemini in your IDE!
Chat with Gemini Code Assist
In this section, you prompt Gemini Code Assist to provide an explanation of your existing code.
To get an explanation of your code, follow these steps:
In your IDE, open your code file.
In the Gemini Code Assist tool window, enter the prompt
Explain this code to me
and click Submit.Gemini Code Assist uses the code in your code file as a reference to your prompt and responds with an explanation of your code.
If you only want an explanation of a certain part of your code, you can select certain code and then prompt Gemini Code Assist again. Gemini Code Assist will only use the selected code as a reference to its generated response.
Here are some other example prompts you can try asking Gemini Code Assist:
Write unit tests for my code.
Help me debug my code.
Make my code more readable.
When Gemini Code Assist provides you with code in its response, you can select the following options listed at the end of its response:
Insert at Cursor: Inserts the generated code into your current file at your current cursor position.
Insert in New File: Opens a new file and inserts the generated code into the new file.
These options are available when Gemini Code Assist identifies the language used in your code block, and if this language is supported in your current IDE.
View query history
If you want to re-use your previous prompts, you can find them in your Query History in the Gemini Code Assist tool window by clicking schedule Show Query History.
Your query and conversation history persist across IDE sessions. To clear query and conversation history, click delete Clear Conversation History.
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 in a code file with a comment
In your code file, on a new line, enter the comment
Function to create a Cloud Storage bucket
.To generate code, press Alt+Shift+\ (for Windows and Linux) or Option+Shift+\ (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.
Prompt Gemini Code Assist with selected code using chat
Gemini Code Assist can perform tasks or answer your questions based on the code that you select. To get generated code that's based on a prompt with selected code, follow these steps:
In the activity bar, click spark Gemini Code Assist to open the Gemini Code Assist tool window.
In your code file, select a block of code.
In the Gemini Code Assist tool window text field, enter a prompt for the selected code.
For example, select a function in your code and enter the prompt
Write a unit test for this function.
Gemini Code Assist uses your selected code as reference and responds to your prompt.
Get code completions
While you write code, Gemini Code Assist makes inline code suggestions, called code completions, that you can either accept or ignore. To get code completions, follow these steps:
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.
Code completion is enabled by default. If you want to disable code completion, in the status bar of your IDE, click spark AI Code Completion: 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 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:
In your code file, select a line or block of code.
Right-click the selected code and select a smart action, like Generate 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.
Exclude files from context
If you want to exclude any of your files from Gemini Code Assist
completions and chat interactions, you can create an .aiexclude
file, which
works similarly to .gitignore
.
For more information on how to configure an .aiexclude
file, see
Configure context sharing with .aiexclude files.
Known issues
The following sections outline the known issues of Gemini Code Assist.
JetBrains code completion shortcut overlaps with Gemini Code Assist shortcut
On JetBrains 2024.2
versions, you may experience the Gemini Code Assist
shortcut key for code generation (Alt+Shift+\ for Windows and Linux,
or Option+Shift+\ for macOS) overlapping with the JetBrains code
completion shortcut that was recently introduced.
To change your shortcut key for Gemini Code Assist, perform the following tasks:
Navigate to settings IDE and Project Settings > Settings > Keymap > Gemini Code Assist.
Right-click Gemini Code Assist and select Add Keyboard Shortcut.
Enter your preferred keyboard shortcut and then click OK.
Right-click Gemini Code Assist and select Remove Alt+Shift+\ (for Windows and Linux), or Remove Option+Shift+\ (for macOS).
You can now use your new keyboard shortcut to generate code in a code file.
Leave feedback
To leave feedback of your experience, follow these steps:
In the status bar, click spark AI Code Completion, and then in the menu, select Submit feedback.
In the text field at the top of the form, enter your feedback.
If you want to share your Gemini Code Assist logs, make sure that you select the log files.
Click Submit Feedback.
What's next
- Learn how to write better prompts.