So we did use the suggestions and completion functionality quite a bit and as you can tell, it works
pretty well.
Now GitHub Copilot is more than just that though.
It also gives you a chat.
You can use a chat integrated into your IDE, though it's not a chat like the one you have in ChatGPT.
Instead, it's really optimized for coding related tasks.
You could try asking some other questions as well, but it's really optimized to help you with coding,
to understand the surrounding context and take it into account, and so on.
And we could use this chat to change this code here a little bit, because one thing we don't have in
here is error handling.
And for example, at the moment when I delete both the backup and the restore database files, if I
run my script here and I try to back up the database, I'm getting an error because there is no database
file.
So we might want to have some error handling in there.
And of course we could add it manually and or in combination with suggestions.
But we can also take advantage of the chat.
Now there are different ways of using the chat.
There is a separate chat panel you can open up in the sidebar.
You can also do that through the command palette here in Visual Studio Code.
Simply type chat in there and choose the open chat command to open this, but we'll not use that sidebar
chat right now, because often the inline chat is much quicker, and you can open that by hitting command
or control I by default, depending on which operating system you are.
And this chat box here should open up now depending on the point of time where you're viewing this,
you might be able to choose which AI model should be used behind the scenes to fulfill your request.
To answer your question and you can experiment with the different options you might have here, which
may change over time to find the one that best suits your needs.
For this course, it doesn't matter which one you choose, because as mentioned earlier, you'll very
likely not get the exact same results as I do anyways.
Now, when I recorded this course, this feature simply didn't exist yet.
But of course this does not impact the other things I show you here, because the way you use the chat
and the tips and tricks I want to share with you haven't changed.
It's also worth noting that you can also attach files or use voice chat here if you wanted to.
You could, for example, attach a screenshot that maybe contains a UI mockup you want to use for your
chat query, but here, to get started, we'll simply use some plain text which you can enter here.
Now you can also open this inline chat here in a couple of other ways.
For example, you can also use the command palette and type inline chat in there and then choose this
editor inline chat option to open it.
You can also right click in the place in your code where you want to use the chat, and go to Copilot
Editor Inline Chat to open it.
Here you also see the shortcut, which depends on the operating system you're on.
You can use to open this chat, and you see a bunch of other options you can use to quickly explain
a part of your code, fix an error in a part of your code, and so on.
But for now, we'll focus on this chat.
Now you can ask any questions in here.
But of course, just as before with the suggestions, it will also take into account the surrounding
code.
To answer this question, or to be precise here with the inline chat.
It's really not about answering the question, but instead about generating code.
You can also use a voice command, or even attach a file like an image, which might contain, um,
a little picture of the UI you want to build or something like that to control which code gets generated.
It's also helpful if you select the code you want to tweak with chat, like here where I am selecting
this backup db function to then tell copilot to add error handling.
Like this.
Now you can add more details, but for a basic start this should be enough.
And if I hit enter, you see it goes ahead and it generates some code.
And it also shows you what it changed.
Now it might be a bit hard to see, but you can maybe see that there are some parts which have a darker
green and a lighter green.
Here, for example, I have a lighter green.
That's the part that did not change.
That's my original code.
The other green parts are the code parts that did change that were added.
You sometimes also have read parts code that's highlighted in red.
That would be code that's removed due to this command you ran.
Now you can then accept those changes or discard them.
You can regenerate it.
Rerun the command to maybe get a different suggestion, different code generation.
And you can also go through various options here.
Toggle changes for example, shows you in greater detail that it's actually going to remove the code
we had and then re-add it down there.
So it's a bit more detailed.
You can also configure the inline chat and that opens up the settings.
And then here you get various settings you can tweak regarding that chat, but we'll take a look at
that later.
So for the moment I'll just hit accept.
And you see it changed the code now.
And it tries to run the code we had before.
But if it fails, it checks which kind of error it is and then outputs a more user friendly error message.
So with that, if I save that code and I again try to run it and back up my database without having
a database file.
You see, now I got this more user friendly error message here instead of that huge error block we had
before.
And that's how we can use this inline chat functionality to tell GitHub Copilot to generate some code
or to tweak some code as we're doing it here.