|
1 | 1 | ---
|
2 | 2 | title: Quick Actions, light bulbs, and screwdrivers
|
3 | 3 | description: Use a single Quick Action in Visual Studio to refactor, generate, or modify your C#, C++, or Visual Basic code files to apply updates and fixes or generate code.
|
4 |
| -ms.date: 08/29/2022 |
5 |
| -ms.topic: conceptual |
| 4 | +ms.date: 08/14/2024 |
| 5 | +ms.topic: concept-article |
6 | 6 | author: Mikejo5000
|
7 | 7 | ms.author: mikejo
|
8 | 8 | manager: mijacobs
|
9 | 9 | ms.subservice: general-ide
|
10 | 10 | dev_langs:
|
11 | 11 | - CSharp
|
12 | 12 | - VB
|
| 13 | + |
| 14 | +#customer intent: As a developer, I want to use Quick Actions in Visual Studio, so I can modify my code files to apply updates and fixes or generate code. |
13 | 15 | ---
|
| 16 | + |
14 | 17 | # Quick Actions
|
15 | 18 |
|
16 |
| -Quick Actions let you easily refactor, generate, or otherwise modify code with a single action. Quick Actions are available for C#, [C++](/cpp/ide/writing-and-refactoring-code-cpp), and Visual Basic code files. Some actions are specific to a language, and others apply to all languages. |
| 19 | +Quick Actions in Visual Studio let you easily refactor, generate, or otherwise modify your code with a single action. Quick Actions are available for C#, [C++](/cpp/ide/writing-and-refactoring-code-cpp), and Visual Basic code files. Some actions are specific to a language, and others apply to all languages. |
17 | 20 |
|
18 | 21 | Quick Actions can be used to:
|
19 | 22 |
|
20 | 23 | - Apply a code fix for a [code analyzer](../code-quality/roslyn-analyzers-overview.md) rule violation
|
21 |
| - |
22 | 24 | - [Suppress](../code-quality/use-roslyn-analyzers.md#suppress-violations) a code analyzer rule violation or [configure](../code-quality/use-roslyn-analyzers.md#set-rule-severity-from-the-light-bulb-menu) its severity
|
| 25 | +- Apply a refactoring, such as [inline for a temporary variable](../ide/reference/inline-temporary-variable.md) |
| 26 | +- Generate code, such as to [introduce a local variable](../ide/reference/introduce-local-variable.md) |
23 | 27 |
|
24 |
| -- Apply a refactoring (for example, [inline a temporary variable](../ide/reference/inline-temporary-variable.md)) |
| 28 | +> [!NOTE] |
| 29 | +> This article applies to Visual Studio on Windows. For Visual Studio for Mac, see [Refactoring (Visual Studio for Mac)](/visualstudio/mac/refactoring). |
25 | 30 |
|
26 |
| -- Generate code (for example, [introduce a local variable](../ide/reference/introduce-local-variable.md)) |
| 31 | +## Understand Quick Action icons |
27 | 32 |
|
28 |
| -> [!NOTE] |
29 |
| -> This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see [Refactoring (Visual Studio for Mac)](/visualstudio/mac/refactoring). |
| 33 | +Visual Studio uses several icons to indicate when Quick Actions are available. The icon type indicates whether the Quick Action is a recommendation or required fix, including refactoring: |
| 34 | + |
| 35 | +- **Screwdriver** : Suggested action to improve your code. |
| 36 | + |
| 37 | +- **Yellow light bulb** : Recommended action to address noncritical issues with your code. |
30 | 38 |
|
31 |
| -Quick Actions can be applied by using the light bulb  or screwdriver  icons, or by pressing **Ctrl**+**.** when your cursor is on a line of code for which an action is available. You'll see an error light bulb  if there's a red squiggle indicating an error and Visual Studio has a fix available for that error. |
| 39 | +- **Error light bulb** : Critical action to fix an error in your code, or apply necessary refactoring. |
32 | 40 |
|
33 |
| -For any language, third parties can provide custom diagnostics and suggestions, for example as part of an SDK, and Visual Studio light bulbs appear based on those rules. |
| 41 | +For any language, third parties can provide custom diagnostics and suggestions, such as part of an SDK. Visual Studio shows light bulbs based on those rules. |
34 | 42 |
|
35 |
| -## Icons |
| 43 | +## Apply recommendations to improve code |
36 | 44 |
|
37 |
| -The icon that appears when a Quick Action is available gives an indication of the type of fix or refactoring that's available. The *screwdriver*  icon indicates just that there are actions available to change the code, but you shouldn't necessarily use them. The *yellow light bulb*  icon indicates there are actions available that you *should* do to improve your code. The *error light bulb*  icon indicates there's an action available that fixes an error in your code. |
| 45 | +When Quick Actions are available, you can select the light bulb  or screwdriver  icon next to the applicable code. |
38 | 46 |
|
39 |
| -## To see a light bulb or screwdriver |
| 47 | +- To see the available improvements, select the Down arrow next to the icon or use the **Show potential fixes** link. |
40 | 48 |
|
41 |
| -If a fix is available, light bulbs appear: |
| 49 | + :::image type="content" source="../ide/media/vs2022-lightbulb-hover-expanded.png" border="false" alt-text="Screenshot that shows the Quick Action recommendation details with the light bulb icon in Visual Studio."::: |
42 | 50 |
|
43 |
| -- When you hover the mouse at the location of an error |
| 51 | +- To apply the recommended change to your code, select the icon. You can also select Ctrl + period (.) when your cursor is on a line of code that shows an available action. |
44 | 52 |
|
45 |
| -  |
| 53 | +## Apply actions to fix errors |
46 | 54 |
|
47 |
| -- In the left margin of the editor when you move the caret (cursor) into the applicable line of code |
| 55 | +If there's an error in your code, and Visual Studio has a recommended fix, you see a red squiggle under the code with the error. The error light bulb  icon also displays next to the marked code. |
48 | 56 |
|
49 |
| -You can also press **Ctrl**+**.** anywhere on a line to see a list of available Quick Actions and refactorings. |
| 57 | +- To see the available fixes, select the Down arrow next to the icon or use the **Show potential fixes** link. |
50 | 58 |
|
51 |
| -To see potential fixes, select either the down arrow next to the light bulb or the **Show potential fixes** link. A list of available Quick Actions is displayed. |
| 59 | + :::image type="content" source="../ide/media/vs2022-error-lightbulb-hover.png" border="false" alt-text="Screenshot that shows the Quick Action potential fix and error light bulb icon in Visual Studio."::: |
52 | 60 |
|
53 |
| - |
| 61 | +- To apply the recommended change to your code, select the icon. You can also select Ctrl + period (.) when your cursor is on a line of code that shows an available action. |
54 | 62 |
|
55 | 63 | > [!TIP]
|
56 |
| -> To learn how to turn off some of the code fix Quick Actions, see [Disable source code analysis for .NET](../code-quality/disable-code-analysis.md). |
| 64 | +> You can turn off some of the code fix Quick Actions. For more informatio, see [Disable source code analysis for .NET](../code-quality/disable-code-analysis.md). |
| 65 | +
|
| 66 | +## Find available actions |
| 67 | + |
| 68 | +You can check your code for available Quick Actions in Visual Studio by scanning for the light bulb , screwdriver , and error light bulb : |
| 69 | + |
| 70 | +- Move your mouse over your code and notice any Quick Action icons: |
| 71 | + |
| 72 | + :::image type="content" source="../ide/media/vs2022-lightbulb-hover.png" border="false" alt-text="Screenshot that shows the basic Quick Action recommendation and light bulb icon in Visual Studio."::: |
| 73 | + |
| 74 | +- Move the insertion cursor (|) into a line of code, and check for Quick Action icons in the left margin of the code editor. |
| 75 | + |
| 76 | +- Select Ctrl + period (.) anywhere on a line for a list of available Quick Actions and refactoring options. |
57 | 77 |
|
58 | 78 | ## Related content
|
59 | 79 |
|
60 | 80 | - [Common Quick Actions](../ide/common-quick-actions.md)
|
61 | 81 | - [Code styles and Quick Actions](../ide/code-styles-and-code-cleanup.md)
|
62 | 82 | - [Visual Studio IntelliCode](/visualstudio/intellicode/intellicode-visual-studio)
|
63 |
| -- [Write and refactor code (C++)](/cpp/ide/writing-and-refactoring-code-cpp) |
|
0 commit comments