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/guided-workshop/exercises/5-coding.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,6 +215,58 @@ With the updates made, you likely want to view the website. Let's start it and s
215
215
216
216
> **IMPORTANT:** You can ignore any **favicon** errors.
217
217
218
+
## Bonus – Using GitHub Copilot Chat
219
+
220
+
> **NOTE:** This section is entirely optional and intended to help you learn more about GitHub Copilot Chat. If this is not of interest, please feel free to progress to the next exercise.
221
+
222
+
In this exercise, we have used GitHub Copilot's Code Completion capabilities to help us stay in the flow and resolve the immediate problem we're trying to solve. Sometimes, we may want an interactive conversation, where we can explore various paths and provide additional context. This is where Copilot Chat can help. Copilot Chat can help us document our code, fix issues and help us in our understanding.
223
+
224
+
There are several ways to interact with Copilot Chat in Visual Studio Code, including the **chat view** and **inline chat**. We'll explore both options.
225
+
226
+
1. Open the existing **Hours.js** file.
227
+
228
+
1. Access the **inline chat view** by pressing <kbd>⌘ (CMD)</kbd>-<kbd>i</kbd> on MacOS, or <kbd>ctl</kbd>-<kbd>i</kbd> on Windows or Linux.
229
+
230
+
1. When using Copilot Chat, you can use [slash commands](https://github.blog/changelog/2024-01-30-code-faster-and-better-with-github-copilots-new-features-in-visual-studio/#slash-commands), such as */fix*, */doc*, */explain* and more. Type **/doc**, to ask Copilot to improve the **Hours.js** file with some additional documentation. You should find that Copilot adds comments which resemble the JSDoc format:
231
+
232
+
```javascript
233
+
/**
234
+
* Renders the component that displays the shelter's hours for the current day.
235
+
*
236
+
* @returns {JSX.Element} The rendered component.
237
+
*/
238
+
```
239
+
240
+
1. The code in the inline chat view is not added to your file until you hit Accept. Once you have reviewed the documentation and you're comfortable, go ahead and click **Accept** to add the suggested changes – enjoy the improved documentation of your code!
241
+
242
+
1. Let's try another slash command. Navigate to the the line where the **today** variable is defined. It should look similar to the below.
243
+
244
+
```javascript
245
+
const today = new Date().toLocaleDateString("en-US", { weekday: "long" });
246
+
```
247
+
248
+
1. Remove **.toLocaleDateString**.
249
+
250
+
1. Select the line that you just changed, and access the **inline chat view** by pressing <kbd>⌘ (CMD)</kbd>-<kbd>i</kbd> on MacOS, or <kbd>ctl</kbd>-<kbd>i</kbd> on Windows or Linux. Type**/fix** and submit the request by pressing <kbd>enter</kbd>. Notice that the inline chat suggests the original line? Go ahead and accept the suggestion.
251
+
252
+
```javascript
253
+
const today = new Date().toLocaleDateString("en-US", { weekday: "long" });
254
+
```
255
+
256
+
1. Let's put Copilot Chat to the test once again. Navigate to the line which defines **todaysHours**. Rename the variable to **openingHours**, but keep all other references to todaysHours the same.
257
+
258
+
1. Try to run the website again by running **npm run dev** in the terminal. After navigating to your site, you should see a runtime error similar to below.
259
+
260
+
```
261
+
⨯ ReferenceError: todaysHours is not defined
262
+
```
263
+
264
+
1. Select the error in the terminal. Now, access Copilot Chat using the **chat view** by clicking the icon in your side bar that resembles a chat icon. In the input box type **/fix #terminalSelection** and submit the message. Copilot should point out that there is a typo in your code, and that you have defined openingHours as the variable but used todaysHours elsewhere (while also providing you with a suggested code snippet to address the issue).
265
+
266
+
1. In addition to slash commands, you can use natural language to interact with Copilot Chat. Consider asking a question like **What does this code do?** or **How could I improve this code?**.
267
+
268
+
Feel free to continue asking questions and refactoring the code as you wish to explore. But before progressing, make sure that the code passes your required tests!
269
+
218
270
## Summary and next steps
219
271
220
272
All developers write code with some form of assistance. This might come from a human pair programmer, copying/pasting code from a developer forum or documentation, or, in our case, and AI pair programer - GitHub Copilot. With GitHub Copilot, developers are able to focus on the bigger tasks while GitHub Copilot provides suggestions and generates code.
0 commit comments