Skip to content

Commit 4ecca65

Browse files
committed
Include samples to demostrate the use of slash commands
1 parent 9038899 commit 4ecca65

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed
Loading
Loading
Loading

06-Using-GitHub-Copilot-with-CSharp/README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GitHub Copilot is the world's first at-scale AI developer tool that significantl
66

77
As a developer, your goal is to boost productivity and speed up coding processes. GitHub Copilot acts as your AI pair programmer, offering suggestions based on context and code patterns. By the end of this module, you'll not only know how to configure GitHub Copilot in Codespaces, but also how to generate and implement code suggestions effectively.
88

9-
Get ready to dive into a real-world scenario! You'll be modifying a C# repository using GitHub Copilot to create an interactive HTML form and an API endpoint. This project will give you valuable experience in developing a C# web app that serves an HTTP API, generating pseudo-random tokens for identification purposes.
9+
Get ready to dive into a real-world scenario! You'll be modifying a C# repository using GitHub Copilot to create an API endpoint. This project will give you valuable experience in developing a C# web app that serves an HTTP API, generating pseudo-random weather forecast information.
1010

1111
</header>
1212

@@ -44,7 +44,7 @@ The "**GitHub Codespaces ♥️ .NET 8**" repository builds a Weather API using
4444
We will review the steps to update the Weather BackEnd App by adding a new endpoint that requests a specific location and returns the weather forecast for that location.
4545

4646

47-
### 🗒️ (Optional Step) : Get familiarized with the "GitHub Codespaces ♥️ .NET 8" repository
47+
### 🗒️ (Optional Step 1) : Get familiarized with the "GitHub Codespaces ♥️ .NET 8" repository
4848

4949
Once you open the repository in Codespaces, you will find a new browser window with a fully functional Codespace. Everything in this repository is contained within this one Codespace. In example, in the explorer panel, we can see the main code for the BackEnd and the FrontEnd project.
5050

@@ -80,6 +80,41 @@ Pressing F10 we can debug step-by-step until line 32, where we can see the gener
8080

8181
Congratulations! Now you are ready to add more features into the app using GitHub Copilot.
8282

83+
### 🗒️ (Optional Step 2) : Get familiarized with GitHub Copilot Slash Commands
84+
85+
As we start working in our codebase, we usually need to refactor some code, or get more context or explanations about it. Using GitHub Copilot Chat, we can have AI-driven conversations to perform these tasks.
86+
87+
Open the file `Program.cs` in the BackEnd project. The file is in the following path `SampleApp\BackEnd\Program.cs`.
88+
89+
Now let's use a slash command, in GitHub Copilot to understand a piece of code. Select lines 22-35, press `CTRL + I` to open the inline chat, and type `/explain`.
90+
91+
![Use slash command to explain a piece of code](./011SlashCommandExplain.gif)
92+
93+
In the Chat Panel, GitHub Copilot will create a detailed explanation of the selected code. A summarized version will be like this one:
94+
95+
```
96+
The selected C# code is part of an ASP.NET Core application using the minimal API feature. It defines a GET endpoint at "/weatherforecast" that generates an array of WeatherForecast objects. Each object is created with a date, a random temperature, and a random summary. The endpoint is named "GetWeatherForecast" and has OpenAPI support for standardized API structure documentation.
97+
```
98+
99+
**Slash commands** are special commands that you can use in chat to perform specific actions on your code. For example, you can use:
100+
- `/doc` to add a documentation comment
101+
- `/explain` to explain the code
102+
- `/fix` to propose a fix for the problems in the selected code
103+
- `/generate` to generate code to answer your question
104+
105+
Let's use the `/tests` command to generate tests to the code. Select lines 39-42, press `CTRL + I` to open the inline chat, and type `/tests` (or select the /tests slash command) to generate a new set of tests for this record.
106+
107+
![Use slash command to generate tests for the selected piece of code](./012SlashCmdTests.gif)
108+
109+
A new class `ProgramTests.cs` was created and added to the project. This tests are using XUnit, however, you can ask to generate tests using another Unit Test library with a command like this one `/tests use MSTests for unit testing`.
110+
111+
Finally, let's use the `/doc` to generate automatic documentation to the code. Select lines 39-42, press `CTRL + I` to open the inline chat, and type `/doc` (or select the command) to generate the documentation for this record.
112+
113+
![Use slash command to generate the documentation for a piece of code](./013SlashCmdDoc.gif)
114+
115+
Inline chat, the Chat Panel, and slash commands are part of the amazing tools that support our development experience with GitHub Copilot. Now we are ready to add new features to this App.
116+
117+
83118
### 🗒️ Step 1: Generate a new Record that includes the city name
84119

85120
Go to the `Program.cs` file in the BackEnd project. The file is in the following path `SampleApp\BackEnd\Program.cs`.

0 commit comments

Comments
 (0)