Now, besides this inline chat here,
Cursor, like GitHub Copilot,
also has this separate chat window,
which you can open with this button
if you highlight some code,
or with this shortcut.
If you have some code selected,
it automatically gets pasted in there
as a reference.
If you have no code selected,
it's just a current file
that's added as a reference.
So as context.
And then again,
you can ask anything,
though this is really not chat GPT
in the editor.
Instead, it is a chat
that focuses on coding-related tasks.
So asking about the weather tomorrow
might work,
but it's definitely not
what this chat is optimized for.
Now, you can add more context here
also by pressing add,
or by pressing the plus here,
which allows you to pick files
that you want to add as context,
so that if you have a question
that actually involves multiple files,
the code from multiple files,
you could easily add that.
But alternatively,
you can also use add files here
to add multiple files
if you wanted to.
So all that is, of course, possible.
You can also refer entire folders
to take a look at all the files
in that folder, for example.
And you can also just start
typing a file name after typing add,
for example, index.js,
to use one of these index.js files
as context.
And you get a preview of that file here.
You can open it
so that you see which kind of context
you're adding to the chat.
And then, just as before,
just as with GitHub Copilot,
you can ask any question here
to get answers about your code
or to generate new code
or adjust the code.
All that is possible
and works pretty much as it did
with GitHub Copilot.
For example, here,
I could refer to my,
let's say, tables.js file.
And I could ask a question here
or give an instruction
and say add a route
that allows people
to edit a reservation
and change the number of people,
time, or date.
Now, if you hit enter,
you confirm this.
If you, however, hit command
or control enter
or whichever shortcut you see here,
then you will also send this message
to cursor,
but it will automatically
take your entire code base
as context.
So then you don't even need
to add a specific file,
at least that's the theory,
because it will automatically
take a look at all your files
or it will automatically try
to use your entire code base
as context.
So that's what I'll do here.
And therefore,
it now takes a look
at these different files,
as you can tell,
and it identifies
the tables.js file correctly.
And in there,
it's now updating the code
to also add a route,
a put route here,
which allows me to edit
an existing reservation.
Now I can click on tables.js
to be taken there
and I can click apply
and then, of course,
I see which changes
are about to be made
so that I can validate them.
I can reject them,
I can accept them,
also by pressing
this shortcut here.
So I'll accept them here
and I added this route.
Now, as always,
you're a developer,
you should take a closer look
at the code
that's generated by AI.
You should make sure
that it works the way it should.
You should feel free
to tweak it.
But of course,
as you can tell,
that's a pretty quick way
of adding code,
in this case,
through the chat.
Instead of through
the suggestions mode.
Both is fine.
It comes down to preference
and to the specific use case,
what you want to use.
And of course,
you'll see more examples later
once we build a complete application
with cursor.