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: docs/debugger/debug-with-copilot.md
+59-7Lines changed: 59 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Debug with GitHub Copilot
3
3
description: Use Copilot to help debug your apps and provide performance insights.
4
-
ms.date: 02/14/2024
4
+
ms.date: 03/04/2024
5
5
ms.topic: how-to
6
6
dev_langs:
7
7
- CSharp
@@ -17,14 +17,17 @@ manager: jmartens
17
17
ms.subservice: ai-tools
18
18
monikerRange: '>= vs-2022'
19
19
---
20
+
20
21
# Debug your app with GitHub Copilot in Visual Studio
21
22
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:
23
26
24
27
- Exceptions
25
28
- Auto Insights for CPU Usage
26
29
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** button.
28
31
29
32
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).
30
33
@@ -40,9 +43,12 @@ To get started, you need:
40
43
> [!NOTE]
41
44
> 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).
42
45
43
-
## Get AI assistance for an exception
46
+
## Get AI assistance to debug your app
44
47
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).
46
52
47
53
### Start a debugging session
48
54
@@ -76,8 +82,54 @@ The following simple example shows how to get AI assistance when you encounter a
1. Press **F5** or select **Start Debugging** from the **Debug** menu.
80
92
93
+
The app pauses at the breakpoint. The Autos window shows that the args variable has a value of `string[0]`.
94
+
95
+

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
+

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
+

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
+

116
+
117
+
Copilot shows a suggested fix to your code.
118
+
119
+

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
+
81
133
An `IndexOutOfRangeException` occurs and the app pauses, showing the exception.
82
134
83
135
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
90
142
91
143
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.
If you have questions about the exception, ask them in the Ask Copilot text box.
94
146
95
147
1. Select the **Preview** button.
96
148
@@ -108,7 +160,7 @@ The following simple example shows how to get AI assistance when you encounter a
108
160
109
161
## Get AI assistance for auto insights
110
162
111
-
Inadditiontointeractivedebuggingassistance, CopilotprovidesdetailedinformationintheCPUUsageautoinsights. Itprovidesinformationandinsightsfor 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.
112
164
113
165
When the CPU Usage tool provides auto insights in the Top Insights section, select **Ask Copilot** to learn from Copilot and start asking questions.
0 commit comments