Chat with Gemini Code Assist Standard and Enterprise

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

  • Receive guidance to help you solve problems with your code.
  • Generate code for your project.
  • Manage the context of your project by specifying files and folders.
  • Create custom commands and rules.

Code customization 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

  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, see Supported coding languages.

  3. If you prefer to use your IDE behind a proxy, see Network 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, see Supported coding languages.

  3. If you prefer to use your IDE behind a proxy, see HTTP Proxy.

Use the Gemini Code Assist chat to explain your code

In this section, you prompt Gemini Code Assist to provide an explanation of your existing code.

VS Code

To get an explanation of your code, follow these steps:

  1. Open your code file.

  2. In the activity bar of your IDE, click spark Gemini Code Assist.

  3. In the Gemini Code Assist pane, enter the prompt Explain this code to me and click send Send.

    Gemini Code Assist uses the code in your code file as a reference to your prompt and responds with an explanation of your code.

    To refer to a specific block of code instead of all the code in the file, you can select the block in your code file and then prompt Gemini Code Assist.

IntelliJ

To get an explanation of your code, follow these steps:

  1. In your IDE, open your code file.

  2. 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.

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.

    Gemini lists code actions at the end of a generated code response.

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.

Gemini Query History in the tool window.

Create multiple chats

You can create multiple chats with Gemini Code Assist which contain their own context separate from other chats. Your chat history shows your first chat and the last updated timestamp. There's a limit of 20 chats. Once you reach this limit, the oldest chat is automatically deleted when you add a new chat.

VS Code

  1. To add a new chat, click add New Chat and enter your prompt in the text field. After you enter the prompt, Gemini Code Assist creates the new chat.
  2. To access your previous chat, click history Resume Previous Chat. A list of your chats appear. Select the chat that you want to view.
  3. To delete a chat thread, click Resume Previous Chat and then click delete Delete next to the chat that you want to delete.

IntelliJ

This feature isn't supported in Gemini Code Assist for IntelliJ and other supported JetBrains IDEs at this time.

Reset chat history

Gemini Code Assist uses the chat history for additional context when responding to your prompts. If your chat history is no longer relevant to what you're trying to achieve, you can reset the chat history.

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:

VS Code

  1. In the activity bar, click spark Gemini Code Assist to open the Gemini Code Assist pane.

  2. In your code file, select a block of code.

  3. In the Gemini Code Assist pane 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 uses your selected code as reference and responds to your prompt.

IntelliJ

  1. In the activity bar, click spark Gemini Code Assist to open the Gemini Code Assist tool window.

  2. In your code file, select a block of code.

  3. 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.

Prompt with specific files and folders in your workspace with local codebase awareness

Local codebase awareness helps you with high quality code suggestions that are syntactically correct and semantically meaningful within the broader context of your codebase, when you specify files or folders for Gemini Code Assist to use as context.

When you specify a folder, Gemini Code Assist uses the files in the folder as well as the files in subfolders as context.

VS Code

To specify files or folders in your chat prompt, type @ and select the file or folder you want to specify.

Specify files and folders with local codebase awareness for VS Code.

To get an explanation on the differences of two files in your codebase, follow these steps:

  1. In the activity bar, click spark Gemini Code Assist.

  2. In the Gemini Code Assist pane, enter the prompt Explain the difference between @YOUR_FILE_NAME_1 and @YOUR_FILE_NAME_2 and press Enter (for Windows and Linux) or Return (for macOS), or Tab. You can also click the name of the file in the list to select the file. Clicking the file name adds the file to your prompt context and opens the file in your IDE.

Gemini Code Assist responds to your prompt while using the two files you specified for context. Gemini Code Assist also includes the files you specified in Context Sources.

Now that you've specified those files, you can continue asking additional questions or prompts in the same chat history, without having to specify the files again.

For example: In the Gemini Code Assist pane, enter the prompt How can I improve YOUR_FILE_NAME_1? (without the @ symbol) and press Enter (for Windows and Linux) or Return (for macOS).

Gemini Code Assist responds to your enquiry about the file you specified in your prompt.

IntelliJ

To specify files or folders in your chat prompt, type @ and select the files or folders you want to specify.

Specify files with local codebase awareness for IntelliJ.

To get an explanation on the differences of two files in your codebase, follow these steps:

  1. In the activity bar, click spark Gemini Code Assist.

  2. In the Gemini Code Assist pane, enter the prompt Explain the difference between @YOUR_FILE_NAME_1 and @YOUR_FILE_NAME_2 and press Enter (for Windows and Linux) or Return (for macOS), or Tab. You can also click the name of the file in the list to select the file. Clicking the file name adds the file to your prompt context and opens the file in your IDE.

Gemini Code Assist responds to your prompt while using the two files you specified for context. Gemini Code Assist also includes the files you specified in Context Sources.

Now that you've specified those files, you can continue asking additional questions or prompts in the same chat history, without having to specify them again.

For example: In the Gemini Code Assist pane, enter the prompt How can I improve YOUR_FILE_NAME_1? (without the @ symbol) and press Enter (for Windows and Linux) or Return (for macOS).

Gemini Code Assist responds to your enquiry about the file you specified in your prompt.

Create custom commands

By default, Gemini Code Assist provides commands like /generate for VS Code and Generate Code for IntelliJ and other supported JetBrains IDEs. You can also create your own custom commands to help you accomplish repetitive tasks faster in your IDE.

In this section, you create a custom command called add-comments that adds comments to the code in your code file. For IntelliJ and other supported JetBrains IDEs, you'll create, save, and execute the custom command from the Prompt Library, and from the in-editor prompt.

VS Code

  1. In your code file, press Control+I (for Windows and Linux) or Command+I (for macOS) to open the Gemini Code Assist Quick Pick menu.

  2. In the menu, search for and select Preferences: Open Settings (UI).

  3. In the Search settings field, enter Geminicodeassist: Custom Commands.

  4. In the Custom Commands box, select Add Item.

  5. In the Item field, enter add-comments as the name of the command.

  6. In the Value field, enter add comments to all functions without comments in my code as the prompt.

  7. Click OK.

You can now use the custom command add-comments in your IDE. The command appears in the list of commands in the Gemini Code Assist Quick Pick menu (Control+I (for Windows and Linux) or Command+I (for macOS)).

IntelliJ

  1. In your IDE, navigate to Settings > Tools > Gemini > Prompt Library.

    Prompt Library for IntelliJ Gemini Code Assist

  2. In the Prompt Library window, click add Add.

  3. Name your custom command add-comments.

  4. In the Prompt Library's text box, enter the prompt: Add comments to all functions without comments in this code.

  5. Select the Show in In-Editor Prompt checkbox if it's unselected.

  6. Click OK to save the custom command in the Prompt Library.

  7. In your code file, highlight the code that you want to modify.

  8. Right-click the highlighted code and navigate to Gemini > Prompt Library and then select the custom command add-comments.

    Gemini Code Assist executes the add-comments command and adds comments to your highlighted code.

You can also invoke the custom command with the in-editor prompt by performing the following tasks:

  1. In your code file, highlight the code that you want to modify, and press Alt+\ (for Windows and Linux) or Cmd+\ (for macOS) to open the Gemini Code Assist Quick Pick menu.

  2. In the menu, select your custom command add-comments.

    Gemini Code Assist executes the add-comments command and adds comments to your highlighted code.

Create rules

You can create rules for Gemini Code Assist to follow, and the rules are included in every chat prompt you enter.

VS Code

  1. In your code file, press Control+I (for Windows and Linux) or Command+I (for macOS) to open the Gemini Code Assist Quick Pick menu.

  2. In the menu, search for and select Preferences: Open Settings (UI).

  3. In the Search settings field, enter Geminicodeassist: Rules.

  4. In the text field, enter a rule such as: Always generate unit tests when creating a new function. You can also add one or more rules with multiple lines in the text field.

    After adding rules in the Rules settings, Gemini Code Assist considers the rule for every prompt or request you make.

    To remove the rule, delete the content from the Rules text field.

IntelliJ

This feature isn't supported in Gemini Code Assist for IntelliJ and other supported JetBrains IDEs at this time.

Known issues

This section outlines the known issues of Gemini Code Assist:

VS Code

  • Chat responses may be truncated when they include an updated version of a large open file

    To work around this issue, select a smaller section of code and include an additional directive in the chat prompt, such as only output the selected code.

  • Vim: Cannot accept or dismiss code generation suggestions unless in insert mode

    When using the Vim plugin in normal mode, you can't accept or dismiss code suggestions.

    To work around this issue, press i to enter insert mode, and then press Tab to accept the suggestion.

  • Vim: Inconsistent behavior when pressing Esc to dismiss suggestions

    When you press Esc, both the IDE and Gemini Code Assist suggestions are dismissed. This behavior is different from the non-Vim behavior where pressing Esc re-triggers Gemini Code Assist.

  • Sign-in attempts keep timing out

    If your sign-in attempts keep timing out, try adding the cloudcode.beta.forceOobLogin setting to your settings.json file:

     "cloudcode.beta.forceOobLogin": true
    
  • License recitation warnings don't persist across sessions

    If license recitation warnings don't persist across sessions, refer to the persistent logs:

    1. Click View > Output.

    2. Select Gemini Code Assist - Citations.

  • Connectivity issues in the Gemini Code Assist output window

    If you see a connection error or other connectivity problems in the Gemini Code Assist output window, try the following:

    • Configure your firewall to allow access to oauth2.googleapis.com and cloudaicompanion.googleapis.com.

    • Configure your firewall to allow communication over HTTP/2, which gRPC uses.

    You can use the grpc-health-probe tool to test connectivity. A successful check results in the following output:

    $ grpc-health-probe -addr cloudaicompanion.googleapis.com:443 -tls error: this server does not implement the grpc health protocol (grpc.health.v1.Health): GRPC target method can't be resolved

    An unsuccessful check results in the following output:

    timeout: failed to connect service "cloudaicompanion.googleapis.com:443" within 1s

    To obtain more details, run the following before grpc-health-probe:

    export GRPC_GO_LOG_SEVERITY_LEVEL=info
    
  • 'Activate Gemini Code Assist' still appears after selecting Gemini Code Assist project

    If you selected your project per the instructions in this guide, which includes enabling the Gemini for Google Cloud API, then there may be an issue with the LS server.

    To find out more details about your issue, perform the following actions:

    1. In the status bar, click spark Gemini Code Assist and then select Send feedback.

    2. Click Show for any of the log files to see more details and to help troubleshoot the issue.

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, follow these steps:

VS Code

  1. In the status bar, click spark Gemini Code Assist, and then in the Quick Pick menu, select Send feedback.

  2. In the form, fill out the Title and Comments fields.

  3. If you want to share your Skaffold or AI Companion logs, make sure that you select the Send Skaffold logs or Send AI Companion logs option.

  4. Click Submit Feedback.

IntelliJ

  1. In the status bar, click spark Gemini Code Assist, and then in the menu, select Submit feedback.

  2. In the text field at the top of the form, enter your feedback.

  3. If you want to share your Gemini Code Assist logs, make sure that you select the log files.

  4. Click Submit Feedback.

What's next