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/3-copilot-instructions.md
+33-12Lines changed: 33 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,15 +21,22 @@ Here are some guidelines to consider when creating a Copilot instructions file:
21
21
- languages, frameworks and libraries in use.
22
22
- required assets to be generated (such as unit tests) and where they should be placed.
23
23
- any language specific rules such as:
24
-
-Python code should always follow PEP8 rules.
25
-
- use arrow functions rather than the `function` keyword.
24
+
-utilize [type hints](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html) in Python.
25
+
- use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) rather than the `function` keyword in TypeScript.
26
26
- If you notice GitHub Copilot consistently provides an unexpected suggestion (e.g. using class components for React), add those notes to the instructions file.
27
27
28
-
Let's create a Copilot instructions file. Just as before, because we want you to explore and experiment, we won't provide exact directions on what to type, but will give enough context to create one on your own.
28
+
Let's create a Copilot instructions file. We'll start by asking Copilot to generate a block of code, then add the instructions file, then ask the same question again to see the changes.
29
29
30
30
1. Return to your IDE with your project open.
31
-
2. Create a new file in the **.github** folder called **copilot-instructions.md**.
32
-
3. Add the markdown to the file necessary which provides information about the project structure and requirements:
31
+
2. Open Copilot Chat and send the following prompt:
32
+
33
+
```
34
+
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
35
+
```
36
+
37
+
3. Note the function signature is similar to `def validate_age(age)` without type hints.
38
+
4. Create a new file in the **.github** folder called **copilot-instructions.md**.
39
+
5. Add the markdown to the file necessary which provides information about the project structure and requirements:
33
40
34
41
```markdown
35
42
# Dog shelter
@@ -39,27 +46,41 @@ Let's create a Copilot instructions file. Just as before, because we want you to
39
46
## Backend
40
47
41
48
- Built using Flask and SQLAlchemy
42
-
- All routes require unit tests, which are created in *test_file.py* in the same folder as the file
43
-
- When creating tests, always mock database calls
49
+
- Use type hints
44
50
45
51
## Frontend
46
52
47
53
- Built using Astro and Svelte
54
+
- TypeScript should use arrow functions rather than the function keyword
48
55
- Pages should be in dark mode with a modern look and feel
49
56
```
50
57
51
-
4. Save the file!
58
+
6. **Save** the file.
52
59
53
60
## Watch the instructions file in action
54
61
55
-
Whenever you make a call to Copilot chat, the references dialog indicates all files used to generate the response. Once you create a Copilot instructions file, you will see it's always included in the references section.
62
+
Whenever you make a call to Copilot chat, the references dialog indicates all files used to generate the response. Once you create a Copilot instructions file, you will see it's always included in the references section. Since you included directions to use type hints, you'll notice the code suggestions will follow this guidance.
56
63
57
-
1. Close all files currently open in VS Code or your Codespace.
64
+
1. Close all files currently open in VS Code or your Codespace. (This will ensure we are working with an empty context.)
58
65
2. Select the `+` icon in GitHub Copilot chat to start a new chat.
59
-
3. Ask Copilot chat **What are the guidelines for the flask app?**
66
+
3. Send Copilot chat the same prompt you used previously:
67
+
68
+
```
69
+
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
70
+
```
71
+
60
72
4. Note the references now includes the instructions file and provides information gathered from it.
61
73
62
-

74
+

75
+
76
+
5. Note the resulting Python now utilizes type hints, and the function signature will resemble the following:
0 commit comments