This document describes how you can use Gemini Code Assist, an AI-powered collaborator in Google Cloud, to help you do the following in your IDE:
- 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 VS Code, Cloud Shell Editor, and Cloud Workstations.
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.
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
. - 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
perform code transformations like /generate function to create a Cloud Storage
bucket
in the Quick Pick menu.
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.
You can also select a part of your code and then prompt Gemini Code Assist for help through the Gemini Code Assist tool window, and receive and accept or reject code suggestions while you code.
Prompt Gemini Code Assist with code transformation
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
/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 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
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 by following these steps:
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+G (for Windows and Linux), or Remove Option+G (for macOS).
You can now use your new keyboard shortcut to generate code in a code file.
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 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 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.
Optional: Exclude files from context with an .aiexclude file
You can exclude files from being considered by Gemini Code Assist
for context by creating an .aiexclude
file. An .aiexclude
file follows the
similar syntax as a .gitignore
file, with the following differences:
- An empty or nonexistent
.aiexclude
file blocks no files in its directory and all sub-directories. - An
.aiexclude
file doesn't support negation, where you prefix patterns with an exclamation point (!
). - An
.aiexclude
file matches greedily on the*
character. This will match indiscriminately on directories and files. This.aiexclude
file doesn't differentiate between**
or*
with regards to folders or files.
Only a single .aiexclude
file is supported currently. To configure your
.aiexclude
file, create a file titled .aiexclude
in the root of your
workspace folder.
Examples
The following examples demonstrate how you can configure an .aiexclude
file:
Block all files named
apikeys.txt
at or below the workspace directory:apikeys.txt
Block all files with the
.key
file extension at or below the workspace directory:*.key
Block only the apikeys.txtfile at the same directory as the
.aiexclude
file, but not any subdirectories:/apikeys.txt
Block all files in the directory
my/sensitive/dir
and all subdirectories. The path should be relative to the workspace root directory.my/sensitive/dir/*
Leave feedback
To leave feedback of your experience, follow these steps:
In the status bar, click spark Gemini Code Assist, 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.
- Learn how Gemini for Google Cloud uses your data.
- Learn about Gemini Code Assist pricing.
- Learn more about Google Cloud compliance.