From the course: Practical GitHub Copilot

Autocompletions panel - Github Copilot Tutorial

From the course: Practical GitHub Copilot

Autocompletions panel

- [Instructor] Copilot shows you solutions on a line by line or solution by solution basis. And most of the time that's okay, but sometimes you want to see different options for the solutions. So, you could do that by pulling up a special panel. And so what I'm going to do here is just delete this particular solution and I'm going to hit command, shift P. That's control shift P on a PC and there's a special completions panel that allows you to see a number of different completions and then lets you choose from the one that you want to use. Now, because my original comment just said to read MP3 files from the directory and list them, it's not putting them into a function. So, if you're not getting what you want, it means that the AI doesn't have enough context. And so what I'll do here is just rewrite my comments a little bit better. So, I'll say create a function that reads MP3 files and let's say, we'll call it audio files in the MP3 format from, and we should probably this on a separate line, the audio directory and returns a list of them. So, the better you can write this, the better it's going to go. Let's try selecting this and I'll hit control enter, which is the shortcut and sometimes, I wanted to show you this, 'cause sometimes it kind of gets stuck. It's supposed to give you 10 solutions and it says it's giving you four but it's really just showing you two. So, I think it's actually going to work better if I don't select the comments. If I just put my cursor after these two comments and then I call that extra panel. So, I'll do control enter again. And now it's synthesizing more solutions for me. Now it only did eight out of 10, which I'm not sure why I didn't do any more. Maybe it just couldn't think of any more. Let's see. So this looks like pretty much the solution that I had before and if you like that solution, all you have to do is hit the accept solution link and it'll replace the code. So, you can actually select some code and replace it if you want to. I think this is pretty much what I want here so let's go ahead and accept that solution. And now I have a few solutions, but what I really love about that panel is that it gives me more than a single option. Some people prefer to use the sort of line by line method. I almost always jump for the list of 10 possible solutions because I think it just gives me a breath of what copilot can get for me from the code. So let's go ahead and finish this up by calling the print method and calling this get audio files method that we created here. And then we will try to run this thing again. You want to make sure that you check things after you program them. Copilot is perfectly capable of doing what's called a hallucination, basically giving you code that looks okay but doesn't actually work. There's only one way to take care of that and that is by making sure you're testing things out.

Contents