Tips of Using Github Copilot as code tool
July 8, 2024
Code
BACKGROUND
In the past two month, Iβve used Github Copilot as my code assistant in frontend coding. Here are some tips so far to use Github Copilot more effectively.
The basic logic of Github Copilot is a GPT trained on codes from Github repositories. It relates to corresponding codes in the repositories to give you coding advices.
Useful tips of using Github Copilot
1 use @workplace
and #file
to introduce context to your problem
@workplace
will search the whole project for answers. It is especially useful when asking conclusive questions, such as βWhere uses next-auth?β. Or it can be seen as a way to do global searchings.2 /explain
- quick search
I used β
/explain
β as a quick way to search files or api documents to understand the functions and variables.3 explain this
- understand errors or output in terminal
Select the errors or output in terminal and right click β
explain this
β. This operation helps me to understand some error codes or debugging info from terminal.
4 /tests
- generate unity test quickly
When generating unity tests , first write down the general info of the tests in the beginning of the file. Then you can use
/tests
to generate tests.Other Tips
- Only open files related to your questions in your editor
- Use semantic variable names and file names
Comparing GPT with Github Copilot
Github Copilot can use CLI such as
#file
and @workplace
to provide context, which can make answers more related to the programming language you use, the framework you use and the functions or libs you use. However, limited context can also mean less connection with similar implements using other programming languages. And sometimes, using GPT can give wider options and answers.
For example, when debugging, using
β/fixβ
prompt in Github copilot gives simple and single answers. Using GPT in this case, may provide you potential causes and more detailed solution.END