「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 生成單元測試)。