「Write a main function where a connection to
DATABASE is created. Include health
checks."
「請以以下結構撰寫 FUNCTION_OR_CLASS:
EXPLAIN_STRUCTURE。」
生成程式碼後,請嘗試使用後續提示詞來改善程式碼:
「請嘗試使用 /fix 指令調整產生的程式碼,例如修正語法錯誤。」
「Add missing imports」(新增缺少的匯入項目)。
「Try /fix on chat-generated code.」
清理、簡化及重構程式碼
在 Gemini Code Assist 對話中試試下列提示:
「Can you merge
IMPORTS_VARIABLES_OR_NOTE_EXPORTED_FUNCTIONS
in this file?」(可以合併這個檔案中的 IMPORTS_VARIABLES_OR_NOTE_EXPORTED_FUNCTIONS 嗎?)
「請簡化 FUNCTION_NAME 函式。」
「Can you merge FUNCTION_NAME_1 and
FUNCTION_NAME_2 into one function?」(你能將 FUNCTION_NAME_1 和 FUNCTION_NAME_2 合併為一個函式嗎?)
「Could you inline some variables in
FUNCTION_NAME?」
「Could you simplify variable naming in the function
FUNCTION_NAME?」(請簡化函式 FUNCTION_NAME 中的變數命名)。
可讀性
在 Gemini Code Assist 對話中試試下列提示:
「請盡可能以較少的程式碼行數編寫 FUNCTION_NAME 函式。」
「Add comments to the function
FUNCTION_NAME.」
「Remove unnecessary whitespaces in the function
FUNCTION_NAME.」(移除函式中不必要的空白字元)。
「Format the function FUNCTION_NAME in a
similar way as the rest of the code.」(以類似其餘程式碼的方式格式化函式 FUNCTION_NAME)。
審查程式碼
在 Gemini Code Assist 對話中試試下列提示:
「將程式碼分成幾個部分,並使用我們的程式碼集說明每個部分。」
「是否有更短且更容易瞭解的變數或關鍵字?」
「Can you give me useful code from the
REPOSITORY_NAME_PACKAGE_MODULE context for
this code?」
「你對函式 FUNCTION_NAME 有何看法?」
偵錯
在 Gemini Code Assist 對話中試試下列提示:
「我在嘗試執行 X/新增 Y 時收到錯誤訊息。為什麼?」
「Can you spot an error in the function
FUNCTION_NAME?」
「How would you fix the function
FUNCTION_NAME given this error
message?」
學習與新手上路
在 Gemini Code Assist 對話中試試下列提示:
"Split this code in parts and explain each of them using our
codebase."
「Show how to call function
FUNCTION_NAME?」
「Show how to run the main function in the
ENVIRONMENT_NAME environment?」
「我們可以在技術上進行哪些重大改良,讓這段程式碼的效能更高?」
「Show me the implementation of
FUNCTION_OR_CLASS_NAME to achieve better
results and add what that specific element is」(顯示 FUNCTION_OR_CLASS_NAME 的實作方式,以獲得更佳結果,並新增該特定元素) - 例如「Show me the implementation of function foo where foo is the name of
the function.」(顯示函式 foo 的實作方式,其中 foo 是函式的名稱)。
遷移
在 Gemini Code Assist 對話中試試下列提示:
「請提供策略,協助我將 FILE_NAME 從 LANGUAGE_1 遷移至 LANGUAGE_2」- 例如從 Go 遷移至 Python。
「Given the function FUNCTION_NAME in
repository REPOSITORY_NAME, find me an
equivalent function in language
LANGUAGE_NAME that I can use.」(在存放區 REPOSITORY_NAME 中,找到與函式 FUNCTION_NAME 等效的函式,並以語言 LANGUAGE_NAME 撰寫,供我使用。)
請嘗試使用提示,透過下列以對話或程式碼生成為基礎的轉換工作流程:
「將以 LANGUAGE_1 編寫的 FILENAME_COMPONENT 程式碼重構並遷移至 LANGUAGE_2」—例如從 Go 遷移至 Python。
遷移部分程式碼後,請嘗試下列做法:
選取較小的區塊,然後使用 /fix 調整至所需狀態。
請嘗試使用下列提示:
「有什麼地方可以改進嗎?」
「Give me possible pain points.」(請列出可能的痛點)。
「如果遷移作業正確無誤,您會如何測試這段程式碼?」
正在生成說明文件
在 Gemini Code Assist 對話中試試下列提示:
「Summarize the code in package or folder
X and provide documentation for the top five
important methods.」
「Generate documentation for
FUNCTION_OR_CLASS_NAME.」(為「<程式碼>」產生文件。)
「縮短文件長度,同時保留重要資訊。」
生成單元測試
在 Gemini Code Assist 對話中試試下列提示:
「Generate unit tests for FILENAME.」(為 FILENAME 生成單元測試)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eGemini Code Assist code customization allows users to receive tailored code recommendations based on their organization's internal libraries, private APIs, and coding style, but is exclusive to the Enterprise subscription.\u003c/p\u003e\n"],["\u003cp\u003eCode customization can be triggered via natural language chat, code generation, code transformation, and autocomplete features within the IDE.\u003c/p\u003e\n"],["\u003cp\u003eThe tool can be used for various coding tasks, including writing new code, refactoring, improving readability, code review, debugging, learning, migration, documentation generation, and unit test generation.\u003c/p\u003e\n"],["\u003cp\u003eBest practices include using relevant variable and function names, avoiding deprecated code in indexed repositories, utilizing code generation for code retrieval, and ensuring necessary includes or imports are present in the file.\u003c/p\u003e\n"],["\u003cp\u003eWhen seeking explanations, migration plans, or error insights, leveraging the chat feature for conversations within the context of the codebase is recommended.\u003c/p\u003e\n"]]],[],null,["# Use Gemini Code Assist code customization\n\n| **Note:** Gemini Code Assist code customization is available only in Gemini Code Assist Enterprise. For more information, see [Gemini Code Assist supported features](/gemini/docs/codeassist/overview#supported-features).\n\nThis document describes how to use\n\n[Gemini Code Assist code customization](/gemini/docs/codeassist/code-customization-overview)\n\nand provides a few best practices. This feature lets you receive code\nrecommendations, which draw from the internal libraries, private APIs, and the\ncoding style of your organization.\n\nBefore you begin\n----------------\n\n1. [Set up Gemini Code Assist](/gemini/docs/discover/set-up-gemini) with an [Enterprise subscription](/gemini/docs/codeassist/overview#supported-features).\n2. [Set up Gemini Code Assist code customization](/gemini/docs/codeassist/code-customization-console).\n\nHow to use code customization\n-----------------------------\n\nThe following table lists ways to use\nGemini Code Assist code customization:\n\nUse cases and prompt examples\n-----------------------------\n\nThe following table provides guidance and examples about using\ncode customization in specific use cases:\n\nBest practices\n--------------\n\n- **Use relevant variable and function names or code snippets.** This guides code customization towards the most pertinent code examples.\n- **Use index repositories that you want to scale, and avoid adding deprecated\n 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.\n- **For code retrieval use cases, use code generation functionality instead of\n code completion** . Prompt using language such as \"Using the definition of \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e, generate the exact same function,\" or \"Generate the exact implementation of \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e.\"\n- **Have includes or imports present in the file for the code that you want to\n retrieve** to improve Gemini contextual awareness.\n- **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.\n- **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.\n- **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.\n- **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.\n\n### **Get more relevant suggestions with remote repository context**\n\nYou can get more contextually aware and relevant code suggestions by directing Gemini Code Assist to focus on specific remote repositories. By using the \u003ckbd\u003e@\u003c/kbd\u003e 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.\n\nTo use a remote repository as context, follow these steps in your IDE's chat:\n\n1. Start your prompt with the \u003ckbd\u003e@\u003c/kbd\u003e symbol. A list of available remote repositories that are indexed will appear.\n2. Select the repository you want to use for context from the list. You can also start typing the repository name to filter the list.\n3. After selecting the repository, write the rest of your prompt.\n\nGemini will then prioritize the selected repository when generating a response.\n\n#### **Example Prompts**\n\nHere are some examples of how you can use this feature:\n\n- **To understand a repository:**\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e What is the overall structure of this repository?\"\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e I'm a new team member. Can you give me an overview of this repository's purpose and key modules?\"\n- **For code generation and modification:**\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e Implement an authentication function similar to the one in this repository.\"\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_NAME\u003c/var\u003e Refactor the following code to follow the conventions in the selected repository.\"\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eREPOSITORY_A_NAME\u003c/var\u003e How can I use the latest functions from this repository to improve my code in \u003cvar translate=\"no\"\u003eREPOSITORY_B_NAME\u003c/var\u003e?\"\n- **For testing:**\n - \"\u003ckbd\u003e@\u003c/kbd\u003e\u003cvar translate=\"no\"\u003eUNIT_TEST_FILE_NAME\u003c/var\u003e Generate unit tests for \u003cvar translate=\"no\"\u003eMODULE\u003c/var\u003e based on the examples in the selected file.\"\n\nBy 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."]]