Skip to content

Commit 119af59

Browse files
committed
Add Copilot to Debugging doc
1 parent 351fb4b commit 119af59

File tree

3 files changed

+87
-53
lines changed

3 files changed

+87
-53
lines changed

docs/editor/debugging.md

Lines changed: 85 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@ MetaSocialImage: images/debugging/debugging-social.png
1010
---
1111
# Debugging
1212

13-
One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile, and debug loop.
13+
One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile, and debug loop. The [Visual Studio Marketplace](https://marketplace.visualstudio.com/vscode/Debuggers) has a wide variety of debugging extensions to add debugging support for other languages and runtimes to VS Code.
1414

15-
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/3HiLLByBWkg" title="Getting started with debugging in VS Code" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
15+
This article describes the debugging features of VS Code and how to get started with debugging in VS Code. You also learn how you can use Copilot in VS Code to accelerate setting up your debugging configuration and starting a debugging session.
16+
17+
> [!TIP]
18+
> Beyond debugging, you can also take advantage of Copilot to help fix problems in your code. Use the `/fix` prompt in Copilot Chat to get suggestions for fixing your code, or use the **Copilot** > **Fix** editor context menu action. Learn more about [using Copilot to fix problems in your code](/docs/copilot/overview.md#fix-issues).
19+
20+
The following video shows how to get started with debugging in VS Code.
21+
22+
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/3HiLLByBWkg" title="Getting started with debugging in VS Code" frameborder="0" allowfullscreen></iframe>
23+
24+
> [!TIP]
25+
> If you don't have a Copilot subscription yet, use Copilot for free by signing up for the [Copilot Free plan](https://github.com/github-copilot/signup). You'll get a monthly limit of completions and chat interactions.
1626
1727
## User interface
1828

@@ -24,6 +34,37 @@ The following diagram shows the main components of the debugging user interface:
2434
1. **Debug toolbar**: has buttons for the most common debugging actions.
2535
1. **Debug console**: enables viewing and interacting with the output of your code running in the debugger.
2636
1. **Debug sidebar**: during a debug session, lets you interact with the call stack, breakpoints, variables, and watch variables.
37+
1. **Run** menu: has the most common run and debug commands.
38+
39+
### Run and Debug view
40+
41+
To bring up the **Run and Debug** view, select the **Run and Debug** icon in the **Activity Bar** on the side of VS Code. You can also use the keyboard shortcut `kb(workbench.view.debug)`.
42+
43+
![Run and Debug icon](images/debugging/run.png)
44+
45+
The **Run and Debug** view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
46+
47+
If running and debugging is not yet configured (no `launch.json` has been created), VS Code shows the Run start view.
48+
49+
![Simplified initial Run and Debug view](images/debugging/debug-start.png)
50+
51+
### Debug actions
52+
53+
Once a debug session starts, the **Debug toolbar** will appear on the top of the window.
54+
55+
![Debug Actions](images/debugging/toolbar.png)
56+
57+
| Action | Explanation |
58+
|--------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
59+
| Continue / Pause <br> `kb(workbench.action.debug.continue)` | **Continue**: Resume normal program/script execution (up to the next breakpoint). <br> **Pause**: Inspect code executing at the current line and debug line-by-line. |
60+
| Step Over <br> `kb(workbench.action.debug.stepOver)` | Execute the next method as a single command without inspecting or following its component steps. |
61+
| Step Into <br> `kb(workbench.action.debug.stepInto)` | Enter the next method to follow its execution line-by-line. |
62+
| Step Out <br> `kb(workbench.action.debug.stepOut)` | When inside a method or subroutine, return to the earlier execution context by completing remaining lines of the current method as though it were a single command. |
63+
| Restart <br> `kb(workbench.action.debug.restart)` | Terminate the current program execution and start debugging again using the current run configuration. |
64+
| Stop <br> `kb(workbench.action.debug.stop)` | Terminate the current program execution. |
65+
66+
> [!TIP]
67+
> Use the `setting(debug.toolBarLocation)` setting to control the location of the debug toolbar. It can be the default `floating`, `docked` to the **Run and Debug** view, or `hidden`. A `floating` debug toolbar can be dragged horizontally and also down to the editor area (up to a certain distance from the top edge).
2768
2869
## Debugger extensions
2970

@@ -35,44 +76,42 @@ Below are several popular extensions, which include debugging support:
3576

3677
<div class="marketplace-extensions-debuggers"></div>
3778

38-
> [!TIP]
39-
> The extensions shown above are dynamically queried. Select an extension tile above to read the description and reviews to decide which extension is best for you.
40-
4179
## Start debugging
4280

43-
The following documentation is based on the built-in [Node.js](https://nodejs.org/) debugger, but most of the concepts and features are applicable to other debuggers as well.
81+
1. Install a [Debugger extension](#debugger-extensions) for your language and runtime.
4482

45-
It is helpful to first create a sample Node.js application before reading about debugging. You can follow the [Node.js walkthrough](/docs/nodejs/nodejs-tutorial.md) to install Node.js and create a simple "Hello World" JavaScript application (`app.js`). Once you have a simple application set up, this page will take you through VS Code debugging features.
83+
VS Code has built-in support for debugging Node.js, JavaScript, and TypeScript.
4684

47-
## Run and Debug view
85+
1. Optionally, configure a `launch.json` [launch configuration](#launch-configurations).
4886

49-
To bring up the **Run and Debug** view, select the **Run and Debug** icon in the **Activity Bar** on the side of VS Code. You can also use the keyboard shortcut `kb(workbench.view.debug)`.
87+
For simple apps, VS Code will try to debug your currently active file without a launch configuration. However, for most debugging scenarios, creating a launch configuration file is needed.
5088

51-
![Run and Debug icon](images/debugging/run.png)
89+
> [!TIP]
90+
> Copilot can help you [create a launch configuration](#generate-a-launch-configuration-with-ai) for your project. Open Copilot Chat and enter the `/startDebugging` chat prompt and Copilot will generate a launch configuration for you. Alternatively, enter a prompt like `generate a launch config for a django app #codebase`.
5291
53-
The **Run and Debug** view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
92+
1. Press `kb(workbench.action.debug.start)`, or press the green play button in the **Run and Debug** view to start a debug session.
5493

55-
If running and debugging is not yet configured (no `launch.json` has been created), VS Code shows the Run start view.
94+
> [!TIP]
95+
> Copilot can help you set up and start a debugging session by using the `copilot-debug` terminal command. Enter `copilot-debug`, followed by the command to run your app to start a debug session. For example, enter `copilot-debug node /bin/www`, or `copilot-debug python app.py` to start a debugging session for a Node.js or Python app.
5696
57-
![Simplified initial Run and Debug view](images/debugging/debug-start.png)
58-
59-
## Run menu
97+
### Run mode
6098

61-
The top-level **Run** menu has the most common run and debug commands:
99+
In addition to debugging a program, VS Code supports **running** the program. The **Debug: Start Without Debugging** action is triggered with `kb(workbench.action.debug.run)` and uses the currently selected launch configuration. Many of the launch configuration attributes are supported in 'Run' mode. VS Code maintains a debug session while the program is running, and pressing the **Stop** button terminates the program.
62100

63-
![Run menu](images/debugging/debug-menu.png)
101+
> [!TIP]
102+
> The **Run** action is always available, but not all debugger extensions support 'Run'. In this case, 'Run' is the same as 'Debug'.
64103
65104
## Launch configurations
66105

67106
To run or debug a simple app in VS Code, select **Run and Debug** on the Debug start view or press `kb(workbench.action.debug.start)` and VS Code will try to run your currently active file.
68107

69-
However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details. VS Code keeps debugging configuration information in a `launch.json` file located in a `.vscode` folder in your workspace (project root folder) or in your [user settings](/docs/editor/debugging.md#global-launch-configuration) or [workspace settings](/docs/editor/multi-root-workspaces.md#workspace-launch-configurations).
108+
However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details. VS Code keeps debugging configuration information in a `launch.json` file located in a `.vscode` folder in your workspace (project root folder), or in your [user settings](/docs/editor/debugging.md#global-launch-configuration) or [workspace settings](/docs/editor/multi-root-workspaces.md#workspace-launch-configurations).
70109

71110
To create a `launch.json` file, select **create a launch.json file** in the Run start view.
72111

73112
![launch configuration](images/debugging/launch-configuration.png)
74113

75-
VS Code will try to automatically detect your debug environment, but if this fails, you will have to choose it manually:
114+
VS Code will try to automatically detect your debug environment, but if this fails, you can choose it manually:
76115

77116
![debug environment selector](images/debugging/debug-environments.png)
78117

@@ -110,6 +149,23 @@ Do not assume that an attribute that is available for one debugger automatically
110149

111150
Review all automatically generated values and make sure that they make sense for your project and debugging environment.
112151

152+
### Generate a launch configuration with AI
153+
154+
With Copilot in VS Code, you can accelerate the process of creating a launch configuration for your project. To generate a launch configuration with Copilot:
155+
156+
1. Open the Chat view with `kb(workbench.action.chat.open)`, or select **Open Chat** from the Copilot menu in the title bar.
157+
158+
1. Enter the `/startDebugging` chat prompt to generate a debug configuration.
159+
160+
Alternatively, you can also enter a custom prompt, like _generate a debug config for an express app #codebase_.
161+
162+
This can be useful if your workspace has files with different languages.
163+
164+
> [!NOTE]
165+
> The `#codebase` chat variable gives Copilot the context of your project, which helps it generate a more accurate response.
166+
167+
1. Apply the suggested configuration, and then start debugging.
168+
113169
### Launch versus attach configurations
114170

115171
In VS Code, there are two core debugging modes, **Launch** and **Attach**, which handle two different workflows and segments of developers. Depending on your workflow, it can be confusing to know what type of configuration is appropriate for your project.
@@ -118,7 +174,7 @@ If you come from a browser Developer Tools background, you might not be used to
118174

119175
The best way to explain the difference between **launch** and **attach** is to think of a **launch** configuration as a recipe for how to start your app in debug mode **before** VS Code attaches to it, while an **attach** configuration is a recipe for how to connect VS Code's debugger to an app or process that's **already** running.
120176

121-
VS Code debuggers typically support launching a program in debug mode or attaching to an already running program in debug mode. Depending on the request (`attach` or `setting(launch)`), different attributes are required, and VS Code's `launch.json` validation and suggestions should help with that.
177+
VS Code debuggers typically support launching a program in debug mode or attaching to an already running program in debug mode. Depending on the request (`attach` or `launch`), different attributes are required, and VS Code's `launch.json` validation and suggestions should help with that.
122178

123179
### Add a new configuration
124180

@@ -144,30 +200,6 @@ In addition, the **debug status** appears in the Status Bar showing the active d
144200

145201
![Debug status](images/debugging/debug-status.png)
146202

147-
## Debug actions
148-
149-
Once a debug session starts, the **Debug toolbar** will appear on the top of the window.
150-
151-
![Debug Actions](images/debugging/toolbar.png)
152-
153-
| Action | Explanation |
154-
|--------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
155-
| Continue / Pause <br> `kb(workbench.action.debug.continue)` | **Continue**: Resume normal program/script execution (up to the next breakpoint). <br> **Pause**: Inspect code executing at the current line and debug line-by-line. |
156-
| Step Over <br> `kb(workbench.action.debug.stepOver)` | Execute the next method as a single command without inspecting or following its component steps. |
157-
| Step Into <br> `kb(workbench.action.debug.stepInto)` | Enter the next method to follow its execution line-by-line. |
158-
| Step Out <br> `kb(workbench.action.debug.stepOut)` | When inside a method or subroutine, return to the earlier execution context by completing remaining lines of the current method as though it were a single command. |
159-
| Restart <br> `kb(workbench.action.debug.restart)` | Terminate the current program execution and start debugging again using the current run configuration. |
160-
| Stop <br> `kb(workbench.action.debug.stop)` | Terminate the current program execution. |
161-
162-
>**Tip**: Use the setting `setting(debug.toolBarLocation)` to control the location of the debug toolbar. It can be the default `floating`, `docked` to the **Run and Debug** view, or `hidden`. A `floating` debug toolbar can be dragged horizontally and also down to the editor area (up to a certain distance from the top edge).
163-
164-
### Run mode
165-
166-
In addition to debugging a program, VS Code supports **running** the program. The **Debug: Start Without Debugging** action is triggered with `kb(workbench.action.debug.run)` and uses the currently selected launch configuration. Many of the launch configuration attributes are supported in 'Run' mode. Visual Studio maintains a debug session while the program is running, and pressing the **Stop** button terminates the program.
167-
168-
> [!TIP]
169-
> The **Run** action is always available, but not all debugger extensions support 'Run'. In this case, 'Run' will be the same as 'Debug'.
170-
171203
## Breakpoints
172204

173205
Breakpoints can be toggled by clicking on the **editor margin** or using `kb(editor.debug.action.toggleBreakpoint)` on the current line. Finer breakpoint control (enable/disable/reapply) can be done in the **Run and Debug** view's **BREAKPOINTS** section.
@@ -234,7 +266,7 @@ Here are some optional attributes available to all launch configurations:
234266
* `presentation` - using the `order`, `group`, and `hidden` attributes in the `presentation` object, you can sort, group, and hide configurations and compounds in the Debug configuration dropdown and in the Debug quick pick.
235267
* `preLaunchTask` - to launch a task before the start of a debug session, set this attribute to the label of a task specified in [tasks.json](/docs/editor/tasks.md) (in the workspace's `.vscode` folder). Or, this can be set to `${defaultBuildTask}` to use your default build task.
236268
* `postDebugTask` - to launch a task at the very end of a debug session, set this attribute to the name of a task specified in [tasks.json](/docs/editor/tasks.md) (in the workspace's `.vscode` folder).
237-
* `internalConsoleOptions` - this attribute controls the visibility of the Debug Console panel during a debugging session.
269+
* `internalConsoleOptions` - this attribute controls the visibility of the Debug console panel during a debugging session.
238270
* `debugServer` - **for debug extension authors only**: this attribute allows you to connect to a specified port instead of launching the debug adapter.
239271
* `serverReadyAction` - if you want to open a URL in a web browser whenever the program under debugging outputs a specific message to the debug console or integrated terminal. For details see section [Automatically open a URI when debugging a server program](#automatically-open-a-uri-when-debugging-a-server-program) below.
240272

@@ -379,7 +411,7 @@ A function breakpoint is created by pressing the **+** button in the **BREAKPOIN
379411

380412
If a debugger supports data breakpoints, they can be set from the context menu in the **VARIABLES** view. The **Break on Value Change/Read/Access** commands add a data breakpoint that is hit when the value of the underlying variable changes/is read/is accessed. Data breakpoints are shown with a red hexagon in the **BREAKPOINTS** section.
381413

382-
## Debug Console REPL
414+
## Debug console REPL
383415

384416
Expressions can be evaluated with the **Debug Console** REPL ([Read-Eval-Print Loop](https://en.wikipedia.org/wiki/Read–eval–print_loop)) feature. To open the Debug Console, use the **Debug Console** action at the top of the Debug pane or use the **View: Debug Console** command (`kb(workbench.debug.action.toggleRepl)`).
385417

@@ -518,7 +550,7 @@ The `uriFormat` property describes how the port number is turned into a URI. The
518550

519551
The resulting URI is then opened outside of VS Code ("externally") with the standard application configured for the URI's scheme.
520552

521-
### Trigger Debugging via Edge or Chrome
553+
### Trigger debugging via Edge or Chrome
522554

523555
Alternatively, the `action` can be set to `debugWithEdge` or `debugWithChrome`. In this mode, a `webRoot` property can be added that is passed to the Chrome or Edge debug session.
524556

@@ -528,7 +560,7 @@ To simplify things a bit, most properties are optional and we use the following
528560
* **uriFormat**: `"http://localhost:%s"`
529561
* **webRoot**: `"${workspaceFolder}"`
530562

531-
### Triggering an Arbitrary Launch Config
563+
### Triggering an arbitrary launch config
532564

533565
In some cases, you might need to configure additional options for the browser debug session, or use a different debugger entirely. You can do this by setting `action` to `startDebugging` with a `name` property set to the name of the launch configuration to start when the `pattern` is matched.
534566

@@ -549,6 +581,11 @@ To see a tutorial on the basics of debugging, check out this video:
549581

550582
* [Getting started with debugging in VS Code](https://www.youtube.com/watch?v=3HiLLByBWkg) - Learn about debugging in VS Code.
551583

584+
To learn more about Copilot and AI-assisted debugging in VS Code:
585+
586+
* [Debugging and fixing issues with Copilot](/docs/copilot/overview.md#fix-issues)
587+
* [Copilot cheat sheet for debugging and fixing issues](/docs/copilot/copilot-vscode-features.md#debug-and-fix-problems)
588+
552589
To learn about debugging support for other programming languages via VS Code extensions:
553590

554591
* [C++](/docs/cpp/cpp-debug.md)

0 commit comments

Comments
 (0)