So, we created this little utility function here to convert Fahrenheit to Celsius.
Now I actually want to have a more flexible function, a function which accepts either
a Fahrenheit or a Celsius value and then maybe some flag that indicates which kind of value
it is and then performs the appropriate conversion depending on which kind of value was passed
in.
So, we could of course try to find a fitting function name which gets GitHub Copilot to
suggest the right function code, but alternatively a very common and useful thing or trick you
can use when working with GitHub Copilot is to add a comment where you describe the kind
of code you want to generate.
So you use the comment almost like a place to put a prompt that will be evaluated by
GitHub Copilot because GitHub Copilot will evaluate the surrounding code around your
cursor when generating the suggestions.
It may even evaluate the entire code in the entire file for generating its suggestions.
So it's smart.
It's taking a look at the surrounding code and that's why you can add a comment here
and say, function that takes either a Celsius or now it even suggests the comment here or
a Fahrenheit temperature and converts it to the average temperature scale.
So yeah, the comment indeed is what I want.
I even get multiple suggestions here.
So maybe I take the shorter one here and I can accept it by hitting tab.
And that's of course kind of next level AI driven development because now I'm writing
a comment for the AI with AI.
And you can probably already see how that may speed up your development flow.
So now here I have that comment.
Actually I'll split it across multiple lines to make it a bit easier to read, to have it
all on the screen.
And you see, I'm getting a suggestion now here.
Even though I did not type a single character, but I'm getting it because of this comment,
which is of course very useful.
By the way, if a suggestion disappears and you want to get it back, it often helps to
just go back a line and then back to the line where you want the code to appear.
So here it now suggests this line of code convert temperature.
Again we have different suggestions here and we can also go to this completions panel to
see if there are maybe more.
Because here, as you saw before, you sometimes have more suggestions than in that quick popup.
And you see now indeed it's loading more suggestions and it generated nine suggestions.
And here you can see, since it seems to take a bit more time when using this panel here,
I got more complete suggestions.
I got the entire code block here instead of just the first line.
So I will say that sometimes you will get entire code blocks here in the main code editor
as well.
It's not always just one line.
It depends on the kind of code it needs to generate and probably also on how fast its
backend currently is.
So here, where it took more time, I got more suggestions and, well, this looks pretty good.
I got the convert temperature function here suggested, which takes a temperature and a
unit identifier, which is either an F or a C, and then it performs the actual conversion.
And I got different variations of that.
So yeah, that looks pretty good.
So I'll take that first suggestion and yeah, sure, save them.
And with that, I got this function here, fully generated by GitHub Copilot because
of my comment, which I now of course can delete.
But adding such comments and use them as a place to write your prompt or your instructions
that define the kind of code that should be generated, that's another very important
trick you should be aware of.
And of course you can use such comments anywhere.
You could use them inside of a function as well to add some extra instructions here,
which could then be picked up by Copilot to generate more code in this place here in the
function.
All that is possible and all these are the little tips and tricks you must be aware of
to use this feature, this extension efficiently.