Skip to main content

Code Actions

Code Actions are a powerful feature of VS Code that provide quick fixes, refactorings, and other code-related suggestions directly within the editor. ProdE integrates with this system to offer AI-powered assistance for common coding tasks.

What are Code Actions?

Code Actions appear as a lightbulb icon (💡) in the editor gutter (the area to the left of the line numbers). They can also be accessed via the right-click context menu, or via keyboard shortcut. They are triggered when:

  • You select a range of code.
  • Your cursor is on a line with a problem (error, warning, or hint).
  • You invoke them via command.

Clicking the lightbulb, right-clicking and selecting "ProdE", or using the keyboard shortcut (Ctrl+. or Cmd+. on macOS, by default), displays a menu of available actions.

ProdE's Code Actions

ProdE provides the following Code Actions:

  • Explain Code: Asks ProdE to explain the selected code. This is useful for understanding unfamiliar code or for getting a high-level overview of a function or class.
  • Fix Code: Asks ProdE to fix problems in the selected code. This action is available when there are diagnostics (errors or warnings) on the selected lines. ProdE will analyze the diagnostics and propose a fix.
  • Improve Code: Asks ProdE to suggest improvements to the selected code. This can include suggestions for better readability, performance, or adherence to best practices.
  • Add to Context: Adds the selected code to the current ProdE conversation, allowing you to refer to it in subsequent messages.

Each of these actions can be performed "in a new task" or "in the current task."

Using Code Actions

There are three main ways to use ProdE's Code Actions:

1. From the Lightbulb (💡)

  1. Select Code: Select the code you want to work with. You can select a single line, multiple lines, or an entire block of code.
  2. Look for the Lightbulb: A lightbulb icon will appear in the gutter next to the selected code (or the line with the error/warning).
  3. Click the Lightbulb: Click the lightbulb icon to open the Code Actions menu.
  4. Choose an Action: Select the desired ProdE action from the menu.
  5. Review and Approve: ProdE will propose a solution in the chat panel. Review the proposed changes and approve or reject them.

2. From the Right-Click Context Menu

  1. Select Code: Select the code you want to work with.
  2. Right-Click: Right-click on the selected code to open the context menu.
  3. Choose "ProdE": Select the "ProdE" option from the context menu. A submenu will appear with the available ProdE actions.
  4. Choose an Action: Select the desired action from the submenu.
  5. Review and Approve: ProdE will propose a solution in the chat panel. Review the proposed changes and approve or reject them.

3. From the Command Palette

  1. Select Code: Select the code you want to work with.
  2. Open the Command Palette: Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  3. Type a Command: Type "ProdE" to filter the commands, then choose the relevant code action (e.g., "ProdE: Explain Code"). You can also type the start of the command, like "ProdE: Explain", and select from the filtered list.
  4. Review and Approve: ProdE will propose a solution in the chat panel. Review the proposed changes and approve or reject them.

Code Actions and Current Task

Each code action gives you two options:

  • in New Task: Select this to begin a conversation with ProdE centered around this code action.
  • in Current Task: If a conversation has already begun, this option will add the code action as an additional message.

Customizing Code Action Prompts

You can customize the prompts used for each Code Action by modifying the "Support Prompts" in the Prompts tab. This allows you to fine-tune the instructions given to the AI model and tailor the responses to your specific needs.

  1. Open the Prompts Tab: Click the icon in the ProdE top menu bar.
  2. Find "Support Prompts": You will see the support prompts, including "Enhance Prompt", "Explain Code", "Fix Code", and "Improve Code".
  3. Edit the Prompts: Modify the text in the text area for the prompt you want to customize. You can use placeholders like ${filePath} and ${selectedText} to include information about the current file and selection.
  4. Click "Done": Save your changes.

By using ProdE's Code Actions, you can quickly get AI-powered assistance directly within your coding workflow. This can save you time and help you write better code.