|
1 | 1 | # Coding with GitHub Copilot |
2 | 2 |
|
3 | | -With code completion, GitHub Copilot provides suggestions in your code editor while you're coding. This can turn comments into code, generate the next line of code, and generate an entire function just from a signature. Code completion helps reduce the amount of boilerplate code and ceremony you need to type, allowing you to focus on the important aspects of what you're creating. |
| 3 | +| [← Workshop setup][walkthrough-previous] | [Next: Helping GitHub Copilot understand context →][walkthrough-next] | |
| 4 | +|:-----------------------------------|------------------------------------------:| |
| 5 | + |
| 6 | + |
| 7 | +With code completions, GitHub Copilot provides suggestions in your code editor while you're coding. This can turn comments into code, generate the next line of code, and generate an entire function just from a signature. Code completion helps reduce the amount of boilerplate code and ceremony you need to type, allowing you to focus on the important aspects of what you're creating. |
4 | 8 |
|
5 | 9 | ## Scenario |
6 | 10 |
|
7 | 11 | It's standard to work in phases when adding functionality to an application. Given that we know we want to allow users to filter the list of dogs based on breed, we'll need to add an endpoint to provide a list of all breeds. Later we'll add the rest of the functionality, but let's focus on this part for now. |
8 | 12 |
|
9 | | -The application uses a Flask app with SQLAlchemy as the backend API (in the [/server](/server/) folder), and an Astro app with Svelte as the frontend (in the [/client](/client/) folder). You will explore more of the project later; this exercise will focus solely on the Flask application. |
| 13 | +The application uses a Flask app with SQLAlchemy as the backend API (in the [/server][server-code] folder), and an Astro app with Svelte as the frontend (in the [/client][client-code] folder). You will explore more of the project later; this exercise will focus solely on the Flask application. |
10 | 14 |
|
11 | 15 | > [!NOTE] |
12 | 16 | > As you begin making changes to the application, there is always a chance a breaking change could be created. If the page stops working, check the terminal window you used previously to start the application for any error messages. You can stop the app by using <kbd>Ctl</kbd>+<kbd>C</kbd>, and restart it by running `./scripts/start-app.sh`. |
13 | 17 |
|
14 | 18 | ## Flask routes |
15 | 19 |
|
16 | | -While we won't be able to provide a full overview of [routing in Flask](https://flask.palletsprojects.com/en/stable/quickstart/#routing), they are defined by using the Python decorator `@app.route`. There are a couple of parameters you can provide to `@app.route`, including the path (or URL) one would use to access the route (such as **api/breeds**), and the [HTTP method(s)](https://www.w3schools.com/tags/ref_httpmethods.asp) which can be used. |
| 20 | +While we won't be able to provide a full overview of [routing in Flask][flask-routing], they are defined by using the Python decorator `@app.route`. There are a couple of parameters you can provide to `@app.route`, including the path (or URL) one would use to access the route (such as **api/breeds**), and the [HTTP method(s)][http-methods] which can be used. |
17 | 21 |
|
18 | 22 | ## Code completion |
19 | 23 |
|
@@ -61,25 +65,38 @@ Let's build our new route in our Flask backend with the help of code completion. |
61 | 65 | return jsonify(breeds_list) |
62 | 66 | ``` |
63 | 67 |
|
64 | | - > [!IMPORTANT] |
65 | | - > Because LLMs are probabilistic, not deterministic, the exact code generated can vary. The above is a representative example. If your code is different, that's just fine as long as it works! |
| 68 | +> [!IMPORTANT] |
| 69 | +> Because LLMs are probabilistic, not deterministic, the exact code generated can vary. The above is a representative example. If your code is different, that's just fine as long as it works! |
66 | 70 |
|
67 | 71 | 8. **Save** the file. |
68 | 72 |
|
69 | 73 | ## Validate the endpoint |
70 | 74 |
|
71 | 75 | With the code created and saved, let's quickly validate the endpoint to ensure it works. |
72 | 76 |
|
73 | | -1. Navigate to [http://localhost:5100/api/breeds](http://localhost:5100/api/breeds) to validate the route. You should see JSON displayed which contains the list of breeds! |
| 77 | +1. Navigate to [http://localhost:5100/api/breeds][breeds-endpoint] to validate the route. You should see JSON displayed which contains the list of breeds! |
74 | 78 |
|
75 | 79 | ## Summary and next steps |
76 | 80 |
|
77 | | -You've added a new endpoint with the help of GitHub Copilot! You saw how Copilot predicted the next block of code you were likely looking for and provided the suggestion inline, helping save you the effort of typing it out manually. Let's start down the path of performing more complex operations by [exploring our project](./2-explore-project.md). |
| 81 | +You've added a new endpoint with the help of GitHub Copilot! You saw how Copilot predicted the next block of code you were likely looking for and provided the suggestion inline, helping save you the effort of typing it out manually. Let's start down the path of performing more complex operations by [exploring our project][walkthrough-next]. |
78 | 82 |
|
79 | 83 | ## Resources |
80 | 84 |
|
81 | | -- [Code suggestions in your IDE with GitHub Copilot](https://docs.github.com/en/copilot/using-github-copilot/getting-code-suggestions-in-your-ide-with-github-copilot) |
82 | | -- [Code completions with GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/ai-powered-suggestions) |
83 | | -- [Prompt crafting](https://code.visualstudio.com/docs/copilot/prompt-crafting) |
| 85 | +- [Code suggestions in your IDE with GitHub Copilot][copilot-suggestions] |
| 86 | +- [Code completions with GitHub Copilot in VS Code][vscode-copilot] |
| 87 | +- [Prompt crafting][prompt-crafting] |
| 88 | + |
| 89 | + |
| 90 | +| [← Workshop setup][walkthrough-previous] | [Next: Helping GitHub Copilot understand context →][walkthrough-next] | |
| 91 | +|:-----------------------------------|------------------------------------------:| |
84 | 92 |
|
85 | | -**NEXT:** [Exercise 2: Explore your project with Copilot](./2-explore-project.md) |
| 93 | +[breeds-endpoint]: http://localhost:5100/api/breeds |
| 94 | +[client-code]: /client/ |
| 95 | +[copilot-suggestions]: https://docs.github.com/en/copilot/using-github-copilot/getting-code-suggestions-in-your-ide-with-github-copilot |
| 96 | +[flask-routing]: https://flask.palletsprojects.com/en/stable/quickstart/#routing |
| 97 | +[http-methods]: https://www.w3schools.com/tags/ref_httpmethods.asp |
| 98 | +[prompt-crafting]: https://code.visualstudio.com/docs/copilot/prompt-crafting |
| 99 | +[server-code]: /server/ |
| 100 | +[vscode-copilot]: https://code.visualstudio.com/docs/copilot/ai-powered-suggestions |
| 101 | +[walkthrough-previous]: ./0-setup.md |
| 102 | +[walkthrough-next]: ./2-explore-project.md |
0 commit comments