Use Gemini Code Assist code customization

This document describes how to use Gemini Code Assist code customization and provides a few best practices. This feature lets you receive code recommendations, which draw from the internal libraries, private APIs, and the coding style of your organization.

Before you begin

  1. Set up Gemini Code Assist with an Enterprise subscription .
  2. Set up Gemini Code Assist code customization .

How to use code customization

The following table lists ways to use Gemini Code Assist code customization:

Remote repository context
  1. Start your prompt with the @ symbol. A list of available remote repositories that are indexed appears.
  2. Select the repository you want to use for context from the list. You can also start typing the repository name to filter the list.
  3. After selecting the repository, write the rest of your prompt.

Consider the following:

  • This is useful when you are working on a task that is mostly related to a specific set of microservices, libraries, or modules.

For more information, see Get more relevant suggestions with remote repository context .

Use cases and prompt examples

The following table provides guidance and examples about using code customization in specific use cases:

Unit test generation

Try the following prompts in Gemini Code Assist chat:

  • "Generate unit tests for FILENAME ."
  • "Add the most relevant test cases for the FUNCTION_NAME function."
  • "Remove test cases that you think don't bring much value."

Best practices

  • Use relevant variable and function names or code snippets.This guides code customization towards the most pertinent code examples.
  • Use index repositories that you want to scale, and avoid adding deprecated functionality.Code customization helps to scale to the code style, patterns, code semantics, knowledge, and implementations across the codebase. Bad examples of repositories to scale are deprecated functionalities, generated code, and legacy implementations.
  • For code retrieval use cases, use code generation functionality instead of code completion. Prompt using language such as "Using the definition of FUNCTION_NAME , generate the exact same function," or "Generate the exact implementation of FUNCTION_NAME ."
  • Have includes or imports present in the file for the code that you want to retrieveto improve Gemini contextual awareness.
  • Execute only one action for each prompt.For example, if you want to retrieve code and have this code be implemented in a new function, perform these steps over two prompts.
  • For use cases where you want more than just code(such as code explanation, migration plan, or error explanation), use code customization for chat, where you have a conversation with Gemini with your codebase in context.
  • Note that AI model generation is non-deterministic. If you aren't satisfied with the response, executing the same prompt again might achieve a better result.
  • Note that generating unit testsgenerally works better if you open the file locally, and then from chat, ask to generate unit tests for this file or a specific function.

Get more relevant suggestions with remote repository context

You can get more contextually aware and relevant code suggestions by directing Gemini Code Assist to focus on specific remote repositories. By using the @ symbol in the chat, you can select one or more repositories to be used as a primary source of context for your prompts. This is useful when you are working on a task that is mostly related to a specific set of microservices, libraries, or modules.

To use a remote repository as context, follow these steps in your IDE's chat:

  1. Start your prompt with the @ symbol. A list of available remote repositories that are indexed will appear.
  2. Select the repository you want to use for context from the list. You can also start typing the repository name to filter the list.
  3. After selecting the repository, write the rest of your prompt.

Gemini will then prioritize the selected repository when generating a response.

Example Prompts

Here are some examples of how you can use this feature:

  • To understand a repository:
    • " @ REPOSITORY_NAME What is the overall structure of this repository?"
    • " @ REPOSITORY_NAME I'm a new team member. Can you give me an overview of this repository's purpose and key modules?"
  • For code generation and modification:
    • " @ REPOSITORY_NAME Implement an authentication function similar to the one in this repository."
    • " @ REPOSITORY_NAME Refactor the following code to follow the conventions in the selected repository."
    • " @ REPOSITORY_A_NAME How can I use the latest functions from this repository to improve my code in REPOSITORY_B_NAME ?"
  • For testing:
    • " @ UNIT_TEST_FILE_NAME Generate unit tests for MODULE based on the examples in the selected file."

By using remote repositories as a focused source of context, you can get more accurate and relevant suggestions from Gemini Code Assist, which can help you code faster and more efficiently.

Create a Mobile Website
View Site in Mobile | Classic
Share by: