Skip to content

Commit 8c01c1c

Browse files
authored
Merge pull request #12260 from Mikejo5000/mikejo-br23
Updates to Debug with Copilot article
2 parents d965f46 + 96353d7 commit 8c01c1c

8 files changed

+59
-7
lines changed

docs/debugger/debug-with-copilot.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Debug with GitHub Copilot
33
description: Use Copilot to help debug your apps and provide performance insights.
4-
ms.date: 02/14/2024
4+
ms.date: 03/04/2024
55
ms.topic: how-to
66
dev_langs:
77
- CSharp
@@ -17,14 +17,17 @@ manager: jmartens
1717
ms.subservice: ai-tools
1818
monikerRange: '>= vs-2022'
1919
---
20+
2021
# Debug your app with GitHub Copilot in Visual Studio
2122

22-
[**GitHub Copilot**](https://marketplace.visualstudio.com/items?itemName=GitHub.copilotvs) and [**GitHub Copilot Chat**](https://aka.ms/VSXGHCopilot) extensions in Visual Studio enable many interactive debugging scenarios, including AI-assisted chat for debugging questions related to your code. Copilot understands call stacks, frames, variable names, and values. As a result, you can ask detailed questions to the debugger-aware Copilot. In addition, Copilot provides an **Ask Copilot** link for AI-assisted help focused on the following scenarios:
23+
In this article, you'll learn how to debug more efficiently using GitHub Copilot. Copilot can provide code fixes along with in-depth analysis and explanations of how code works. It helps with proposed fixes to bugs, and explains things such as exceptions. Copilot understands call stacks, frames, variable names, and values. As a result, you can interact with the debugger-aware AI to ask detailed questions related to your code and to debugging issues in general.
24+
25+
In addition, Copilot provides more precise help for a few targeted scenarios including the following:
2326

2427
- Exceptions
2528
- Auto Insights for CPU Usage
2629

27-
In this article, you'll learn how to debug more efficiently using the Copilot Chat extension and the **Ask Copilot** link.
30+
To get AI assistance While you're debugging in these scenarios, look for the **Ask Copilot** ![Screenshot of Ask Copilot button.](../debugger/media/vs-2022/debug-with-copilot-ask-copilot-button.png) button.
2831

2932
For more information on the GitHub Copilot extension in Visual Studio, see [About the GitHub Copilot extension for Visual Studio](../ide/visual-studio-github-copilot-extension.md).
3033

@@ -40,9 +43,12 @@ To get started, you need:
4043
> [!NOTE]
4144
> If you experience authentication issues after installing the extension, see [Troubleshooting authentication issues with GitHub Copilot Chat](https://docs.github.com/en/copilot/troubleshooting-github-copilot/troubleshooting-authentication-issues-with-github-copilot-chat).
4245
43-
## Get AI assistance for an exception
46+
## Get AI assistance to debug your app
4447

45-
The following simple example shows how to get AI assistance when you encounter an exception and how to quickly update your code based on AI-suggested fixes.
48+
The following simple example shows how to get AI assistance using the inline Chat view.
49+
50+
> [!NOTE]
51+
> You can also get help using the separate Chat window by selecting **View > GitHub Copilot Chat**. For more information, see [What is the GitHub Copilot Chat extension for Visual Studio?](../ide/visual-studio-github-copilot-chat.md).
4652
4753
### Start a debugging session
4854

@@ -76,8 +82,54 @@ The following simple example shows how to get AI assistance when you encounter a
7682
}
7783
```
7884

85+
1. Right-click the following statement and choose **Breakpoint** > **Insert Breakpoint**.
86+
87+
```csharp
88+
int value = Int32.Parse(args[0]);
89+
```
90+
7991
1. Press **F5** or select **Start Debugging** from the **Debug** menu.
8092

93+
The app pauses at the breakpoint. The Autos window shows that the args variable has a value of `string[0]`.
94+
95+
![Screenshot of Autos window.](../debugger/media/vs-2022/debug-with-copilot-autos-window.png)
96+
97+
1. Right-click in the code and choose **Ask Copilot** to open the inline Chat view.
98+
99+
1. Type the following question in the inline Chat view:
100+
101+
```
102+
Why does the args variable have a value of string[0]?
103+
```
104+
105+
![Screenshot of inline Copilot Chat.](../debugger/media/vs-2022/debug-with-copilot-inline-chat.png)
106+
107+
When you press **Enter**, Copilot provides an answer based on its understanding of your code. (You might get a different response than what is shown here.)
108+
109+
![Screenshot of Copilot answered question.](../debugger/media/vs-2022/debug-with-copilot-inline-chat-answer.png)
110+
111+
If Copilot has a suggested fix for your code, it shows you. If not, you can ask Copilot for a code suggestion.
112+
113+
1. In this example, scroll to the end of the Copilot answer and select the follow-up question at the end of the inline Chat window, "How can I handle the case when no arguments are passed to the program?"
114+
115+
![Screenshot of Copilot follow-up question.](../debugger/media/vs-2022/debug-with-copilot-inline-chat-generated-question.png)
116+
117+
Copilot shows a suggested fix to your code.
118+
119+
![Screenshot of Copilot suggested fix.](../debugger/media/vs-2022/debug-with-copilot-inline-chat-suggested-fix.png)
120+
121+
If you want to apply the code fix, choose **Accept**.
122+
123+
1. Choose **Cancel** so we can continue learning other features of Copilot in the next section.
124+
125+
## Get AI assistance for an exception
126+
127+
The following simple example shows how to get AI assistance when you encounter an exception and how to quickly update your code based on AI-suggested fixes.
128+
129+
### Start a debugging session
130+
131+
- While paused in the debugger using the same sample app, press **F11** or **Debug** > **Step Into** to execute the current statement.
132+
81133
An `IndexOutOfRangeException` occurs and the app pauses, showing the exception.
82134

83135
To get AI assistance for the exception, continue to the next section.
@@ -90,7 +142,7 @@ The following simple example shows how to get AI assistance when you encounter a
90142

91143
If it's not already open, the Copilot Chat window appears and provides an assessment of the error and why it occurred. In this example, Copilot identifies a suggested code fix, a button to copy code, and a **Preview** button for the code fix.
92144

93-
If you have questions about the exception, ask them in the Ask Copilot text box. Copilot understands debugging concepts such as call stacks, frames, variable names, and values.
145+
If you have questions about the exception, ask them in the Ask Copilot text box.
94146

95147
1. Select the **Preview** button.
96148

@@ -108,7 +160,7 @@ The following simple example shows how to get AI assistance when you encounter a
108160

109161
## Get AI assistance for auto insights
110162

111-
In addition to interactive debugging assistance, Copilot provides detailed information in the CPU Usage auto insights. It provides information and insights for specific methods and properties, such as `String.Concat` and many other methods. With Copilot, ask questions about functions on the identified hot paths in your code, which can help you produce more efficient or cost-effective code.
163+
In addition to interactive debugging assistance, Copilot provides detailed information in the CPU Usage [Auto Insights](../profiling/cpu-insights.md). It provides information and insights related to a set of specific performance insights. With Copilot, ask questions about functions on the identified hot paths in your code, which can help you produce more efficient or cost-effective code.
112164

113165
When the CPU Usage tool provides auto insights in the Top Insights section, select **Ask Copilot** to learn from Copilot and start asking questions.
114166

Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)