⏲️ Est. time to complete: 15 min. ⏲️
Today you will learn how to:
- Adding github copilot to your codespace
- Adding a footer to the application
- Generate code with Github Copilot
- Explain code with Github Copilot
In this challenge, we'll delve into refining our code by initiating a new pull request while exploring the capabilities of GitHub Copilot, an AI-driven coding assistant. Our aim is to integrate a footer into our application with the aid of this tool. Let's kickstart the process by integrating GitHub Copilot into our Codespace environment.
Here are the steps to follow:
- Navigate to the extensions marketplace and search for GitHub Copilot.
- Click on the "Install" button to add it to our environment.
- Verify the installation by testing its functionality: Open any file within the repository and, at any point in the code, press Ctrl+I. If a prompt appears for Copilot to generate code, then the installation is successfully completed!
A website footer is a section located at the bottom of a web page. It often contains links or copyright notices. Our goal is to incorporate this section into the application. Let's start this process by creating a new branch:
- Within our Codespace environment, in the terminal type the command
git checkout -b add-footer
. This command will create a new branch named add-footer and automatically switch you to this newly created branch. - Navigate to the file located at frontend > src > App.vue.
- Inside this file, locate the closing tag, you can find it at line 11. Beneath it, insert the following code snippet:
<footer>Made with love ❤️</footer>
. This addition will integrate a footer section into our application.
Following what we learnt in our previous challenges, it's crucial to test our changes within the Codespace environment to ensure everything functions as expected. To do this:
- In the terminal, change the directory to the frontend folder by executing
cd frontend
. - run the command
npm run dev
to start the development server. - click on Run in Browser to launch the application in your preferred browser. Once loaded, scroll down to the bottom of the application interface and you should now be able to see the newly added footer.
The current footer has some display issues which we will try to fix with github copilot!
You might have noticed that the footer lacks any visual styling and that when you release the scroll bar, the footer quickly disappears back into the main section of the application. Cascading Style Sheets (CSS) is a fundamental language in web development used to manipulate the visual presentation of web pages, including elements like layout, colors, and fonts.
Now, let's consider the scenario where you're a developer who has no experience in working with CSS but still wants to enhance the appearance of the footer and wants to fix the scroll bar problem. This is where GitHub Copilot becomes incredibly useful!
- Remove the line of code we added at line 12
<footer>Made with love ❤️</footer>
- Select all the code using Ctrl+A then press on Ctrl+I, write in the prompt bar Please add a footer to this application that has the text "Made with love ❤️" and please add proper styling
- Copilot will generate code suggestions. Click on "Accept".
- re-run the application with
npm run dev
and view the page again, you should now see the footer with styling and the scrollbar problem should disappear.
Github Copilot might generate different results for every participant. Please expect that your user interface might look different than the one shown in the picture. If you have any issues with the generated code, feel free to ask the instructors. |
GitHub Copilot serves as a great tool not only for coding but also for understanding unfamiliar sections of code. Its capabilities extend beyond simple code generation; it can assist with bug fixing, code documentation generation, and even test creation.
Now, let's delve into how GitHub Copilot explains code. Follow these steps:
- Identify a section of code that presents a challenge or that you don't fully grasp, such as the
.footer
styling segment. - Press Ctrl+I and type /explain. This action triggers a list of commands, including /tests, /fix, and /docs.
- Upon hitting enter, you'll see an explanation in the chat section of GitHub Copilot, located in the sidebar on the left. This chat interface allows you to interact with Copilot conversationally as long as you ask programming-related queries. Thus, it won't provide information on non-programming topics, such as where to purchase a new guitar.
Before we move on to the next challenge, try engaging more with Copilot. Explore clarification on various sections of the code that may be interesting to you. Don't hesitate to experiment with different commands and leverage Copilot's capabilities to generate new code snippets. Each time you make a modification, make sure to test it to observe its impact on the application.