You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/1-hour/4-add-feature.md
+40-13Lines changed: 40 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,37 +8,57 @@ The website currently lists all dogs in the database. While this was appropriate
8
8
9
9
## Copilot Edits
10
10
11
-
Previously we utilized Copilot chat to work with an individual file. However, most updates necessitate changes to multiple files throughout a codebase. Even a seemingly basic change to a webpage likely requires updating HTML, CSS and JavaScript files. Copilot Edits allows you to modify multiple files at once.
11
+
Previously we utilized Copilot chat, which is great for working with an individual file or asking questions about our code. However, many updates necessitate changes to multiple files throughout a codebase. Even a seemingly basic change to a webpage likely requires updating HTML, CSS and JavaScript files. Copilot Edits allows you to modify multiple files at once.
12
12
13
13
With Copilot Edits, you will add the files which need to be updated to the context. Once you provide the prompt, Copilot Edits will begin the updates across all files in the context. It also has the ability to create new files or add files to the context as it deems appropriate.
14
14
15
-
## Add the filters to the page
15
+
## Add the filters to the dog list page
16
16
17
17
Adding the filters to the page will require updating a minimum of two files - the Flask backend and the Svelte frontend. Fortunately, Copilot Edits can update multiple files! Let's get our page updated with the help of Copilot Edits.
18
18
19
19
> [!NOTE]
20
20
> Because Copilot Edits works best with auto-save enabled, we'll activate it. As we'll explore a little later in this exercise, Copilot Edits provides powerful tools to undo any changes you might not wish to keep.
21
21
22
-
1. Enable Auto Save by selecting **File** > **Auto Save**.
23
-
2. Open the following files in your IDE (which we'll point Copilot chat to for context):
22
+
1. Return to your IDE with your project open.
23
+
2. Close any tabs you have open inside your IDE.
24
+
3. Enable Auto Save by selecting **File** > **Auto Save**.
25
+
4. Open the following files in your IDE (which we'll point Copilot chat to for context):
24
26
-**server/app.py**
25
27
-**client/src/components/DogList.svelte**
26
-
3. Select **Copilot Edits** in the Copilot Chat window.
27
-
4. If available, select **Claude 3.5 Sonnet** from the list of available models.
28
-
5. Select **Add Context...** in the chat window.
29
-
6. Select **Open Editors** from the prompt. This will add all currently open files to the context.
30
-
7. Ask Copilot to perform the operation you want, to update the pageto add the filters. It should meet the following requirements:
28
+
5. Select **Copilot Edits** in the Copilot Chat window.
29
+
6. If available, select **Claude 3.5 Sonnet** from the list of available models.
30
+
7. Select **Add Context...** in the chat window.
31
+
7. Select **Open Editors** from the prompt. This will add all currently open files to the context.
32
+
8. Ask Copilot to generate the update you want to the page, which is to add filters for both dog breed and if dogs are available for adoption. Use your own phrasing, ensuring the following requirements are met:
31
33
- A dropdown list should be provided with all breeds
32
34
- A checkbox should be available to only show available dogs
33
35
- The page should automatically refresh whenever a change is made
34
36
37
+
> [!NOTE]
38
+
> You should use your own phrasing when generating the prompt. As highlighted previously, part of the exercise is to become comfortable creating prompts for GitHub Copilot. One key tip is it's always good to provide more guidance to ensure you get the code you are looking for.
39
+
35
40
Copilot begins generating the suggestions!
36
41
37
42
## Reviewing the suggestions
38
43
39
44
Unlike our prior examples where we worked with an individual file, we're now working with changes across multiple files - and maybe multiple sections of multiple files. Fortunately, Copilot Edits has functionality to help streamline this process.
40
45
41
-
As the code is generated, you will notice the files are displayed using an experience similar to diff files, with the new code highlighted in green and old code highlighted in red (by default). You'll also notice interfaces which allow you to select a checkbox to accept individual changes, and **Keep** buttons to accept changes for an individual file or across all updates.
46
+
GitHub Copilot will propose the following changes:
47
+
48
+
- Update the endpoint to list all dogs to accept parameters for breed and availability.
49
+
- Update the webpage to include the dropdown list and checkbox.
50
+
51
+
As the code is generated, you will notice the files are displayed using an experience similar to diff files, with the new code highlighted in green and old code highlighted in red (by default).
52
+
53
+
If you open an individual file, you can keep or undo changes by using the buttons provided.
54
+
55
+

56
+
57
+
You can also keep or undo all changes made.
58
+
59
+

60
+
61
+
And
42
62
43
63
1. Review the code suggestions to ensure they behave the way you expect them to, making any necessary changes. Once you're satisfied, you can select **Keep** on the files individually or in Copilot Chat to accept all changes.
44
64
2. Open the page at [http://localhost:4321](http://localhost:4321) to see the updates!
@@ -47,14 +67,21 @@ As the code is generated, you will notice the files are displayed using an exper
47
67
48
68
> [!IMPORTANT]
49
69
> Working iteratively a normal aspect of coding with an AI pair programmer. You can always provide more context to ensure Copilot understands, make additional requests, or rephrase your original prompts. To aid you in working iteratively, you will notice undo and redo buttons towards the top of the Copilot Edits interface, which allow you to move back and forth across prompts.
70
+
>
71
+
> 
50
72
51
-
5. Optional: Disable Auto Save by unselecting **File** > **Auto Save**.
73
+
5. Confirm the functionality works as expected, then select **Keep** to accept all the changes.
74
+
6. Optional: Disable Auto Save by unselecting **File** > **Auto Save**.
52
75
53
76
## Summary
54
77
55
-
Congratulations! You've worked with GitHub Copilot to add new features to the website - the ability to filter the list of dogs.
78
+
You've worked with GitHub Copilot to add new features to the website - the ability to filter the list of dogs. With the help of Copilot Edits, you updated multiple files across the project, and iteratively built the desired functionality.
79
+
80
+
## Workshop review
81
+
82
+
Over the course of the workshop you explore the core functionality of GitHub Copilot. You saw how to use code completion to get inline suggestions, chat participants to explore your project, Copilot instructions to add context, and Copilot Edits to update multiple files.
56
83
57
-
##
84
+
There is no one right way to use GitHub Copilot. Continue to explore and try different prompts to discover what works best for your workflow and how GitHub Copilot can aid your productivity.
0 commit comments