From the course: Software Testing Assistance with GitHub Copilot AI

Copilot for code completion - Github Copilot Tutorial

From the course: Software Testing Assistance with GitHub Copilot AI

Copilot for code completion

- [Instructor] Code completion is where you will interact with CoPilot the most. Once installed, CoPilot will start suggesting code immediately. Code completion can mean a lot of things. There are times where CoPilot will understand you returning a bull and complete a conditional for you. Other times you can type a comment and CoPilot will attempt to infer your meaning and provide code for that. Here's a simple example in PHP. I'll start a function and give it a simple name, alphabetize by last name and I'll type hint it as an array of names. There are a ton of ways to solve this problem. You can probably think of two or three, along with questions about the data format in the array. For now, we'll take co-pilot's approach. Another approach to prompt and co-pilot is to write a comment. I'll add a comment here. Validate the string is an email address. The ghost text shows a suggestion of a function, but I can be more explicit in my comment and suggest I want to reg exit. Being AI sometimes it's difficult to work with and there's ways we can solve this. Generally in this course, I'm not going to use frameworks, but for the purpose of this example, I think it's helpful. This is a Laravel model for a blog post. It has title, content, and an author id. I run the command to create a migration, and now I need to go populate the migration. When I'm in the migration file Co-pilot knows about the post model and suggests appropriate columns. CoPilot doesn't really care how you prompt it For code completion, I started a function and it made a suggestion. I wrote a comment and it made a suggestion, an incorrect one, but a suggestion. Finally, I created a new file that has a relationship with another file and it made a suggestion. Code completion is powerful. It takes a little getting used to, and you can't blindly accept everything CoPilot suggests, but it will increase your output significantly.

Contents