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
- Set up Gemini Code Assist with an Enterprise subscription.
- Set up Gemini Code Assist code customization with an Enterprise subscription.
How to use code customization
The following table lists ways to use Gemini Code Assist code customization:
Form | How to trigger | Notes and resources |
---|---|---|
Natural language chat |
Enter a natural language prompt in Gemini Code Assist chat in the IDE. |
Consider the following:
For more information, see Chat with Gemini Code Assist. |
Generate code | In the quick pick bar in your IDE, either with or without selected code, press Command+Enter (on macOS) or Control+Enter. | For more information, see Generate code with prompts. |
Transform code | In the quick pick bar in your IDE, either with or without
selected code, enter /fix . |
For more information, see Generate code with prompts. |
Autocomplete | Code customization is automatically triggered and provides suggestions based on what you write. | Consider the following:
For more information, see Get code completions. |
Use cases and prompt examples
The following table provides guidance and examples about using code customization in specific use cases:
Use case | Things worth trying |
---|---|
Writing new code |
Try the following to generate code in your IDE or Gemini Code Assist chat:
Try generating code with the following prompts in Gemini Code Assist chat:
After you generate some code, try using a follow-up prompt to improve it:
|
Cleaning, simplifying, and refactoring code |
Try the following prompts in Gemini Code Assist chat:
|
Readability |
Try the following prompts in Gemini Code Assist chat:
|
Code review |
Try the following prompts in Gemini Code Assist chat:
|
Debugging |
Try the following prompts in Gemini Code Assist chat:
|
Learning and onboarding |
Try the following prompts in Gemini Code Assist chat:
|
Migration |
Try the following prompts in Gemini Code Assist chat:
Try the following chat-based or code generation transformation workflow using prompts:
|
Generating documentation |
Try the following prompts in Gemini Code Assist chat:
|
Unit test generation |
Try the following prompts in Gemini Code Assist chat:
|
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 ofFUNCTION_NAME
." - Have includes or imports present in the file for the code that you want to retrieve to 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 tests generally works better if you open the file locally, and then from chat, ask to generate unit tests for this file or a specific function.