Code Actions

Code Actions deliver immediate AI-powered assistance from the Gamecraft Agent right inside your code editor through Gamecraft's built-in lightbulb system.ing Soon

This intelligent feature recognizes coding contexts automatically and presents relevant AI actions, eliminating the need to navigate away from your code to access the chat interface.

Understanding Code Actions

Code Actions manifest as a lightbulb icon (💡) in the editor's left margin, known as the gutter. You can also reach them through the right-click context menu, keyboard shortcuts, or the command palette. These actions activate when:

  • You highlight a section of code

  • Your cursor rests on a line containing issues (errors, warnings, or suggestions)

  • You manually trigger them through commands

Activating the lightbulb, right-clicking and choosing "Gamecraft Agent", or pressing the default keyboard shortcut (Ctrl+. on Windows/Linux, Cmd+. on macOS) reveals a menu of available actions.

Gamecraft Agent Code Actions

Gamecraft Agent offers five distinct code actions, each appearing based on the current context and situation:

Right-Click Context Actions

  • Add to Context: Seamlessly incorporates your selected code into the Gamecraft Agent conversation, complete with file names and line numbers for precise location tracking. This action appears first in the menu for quick access.

  • Explain Code: Requests the Gamecraft Agent to provide detailed explanations of your selected code segments.

  • Improve Code: Prompts the Gamecraft Agent to analyze and suggest enhancements for your selected code.

Extended Actions

  • Fix Code: Available through the lightbulb interface and command palette (excluded from right-click menu). Directs the Gamecraft Agent to resolve issues in your selected code.

  • New Task: Generates a new development task incorporating your selected code. Accessible via the command palette.

Smart Context Detection

The lightbulb menu adapts intelligently, displaying relevant actions based on your code's current condition:

For Problematic Code (when Visual Studio Code displays red or yellow underlines):

  • Fix Code - Receive detailed guidance to address specific errors or warnings

  • Add to Context - Include the problematic code in the Gamecraft Agent's context for collaborative problem-solving

For Clean Code (no diagnostic issues):

  • Explain Code - Obtain comprehensive explanations of code functionality

  • Improve Code - Get optimization recommendations and coding best practices

  • Add to Context - Include the code in the Gamecraft Agent's context for continued development

Deep Dive: Add to Context

The Add to Context action occupies the top position in the Code Actions menu, enabling rapid code snippet integration into your conversation. When activated, the Gamecraft Agent automatically includes file names and line numbers alongside your code.

This contextual information helps the Gamecraft Agent understand your code's precise location within the project structure, enabling more targeted and accurate assistance.

Example Integration:

(Where @myFile.js:15:25 represents code added through "Add to Context")

How to Use Code Actions

You can access the Gamecraft Agent's Code Actions through three primary methods:

Method 1: Lightbulb Interface (💡)

  1. Select Your Code: Highlight the code you want to work with - this can be a single line, multiple lines, or entire code blocks.

  2. Locate the Lightbulb: A lightbulb icon will appear in the editor's left margin adjacent to your selected code (or the line containing errors/warnings).

  3. Activate the Lightbulb: Click the lightbulb icon to reveal the Code Actions menu.

  4. Select an Action: Choose your desired Gamecraft Agent action from the displayed options.

  5. Review and Decide: The Gamecraft Agent will present a solution in the chat panel. Examine the proposed changes and either approve or reject them.

Method 2: Right-Click Context Menu

  1. Select Your Code: Highlight the code section you want to work with.

  2. Access Context Menu: Right-click on your selected code to open the context menu.

  3. Choose Gamecraft Agent: Select the "Gamecraft Agent" option from the context menu. A submenu will display the available actions.

  4. Pick an Action: Choose your desired action from the submenu options.

  5. Review and Decide: The Gamecraft Agent will present a solution in the chat panel. Examine the proposed changes and either approve or reject them.

Method 3: Command Palette

  1. Select Your Code: Highlight the code you want to work with.

  2. Open Command Palette: Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).

  3. Search Commands: Type "Gamecraft Agent" to filter available commands, then select the appropriate code action (such as "Gamecraft Agent: Explain Code"). The action will execute in the most relevant context (typically the currently active chat task, if available).

  4. Review and Decide: The Gamecraft Agent will present a solution in the chat panel. Examine the proposed changes and either approve or reject them.

Terminal Actions

The Gamecraft Agent extends its Code Actions functionality to terminal interactions with comparable features:

  • Terminal: Add to Context: Incorporates selected terminal output directly into your chat conversation

  • Terminal: Fix Command: Requests the Gamecraft Agent to troubleshoot and resolve failed terminal commands

  • Terminal: Explain Command: Asks the Gamecraft Agent to clarify terminal output or explain command functionality

Access these actions by selecting text within the terminal and right-clicking to open the context menu.

Managing Code Actions

Control Code Actions behavior through Gamecraft's settings system:

Enable or Disable Code Actions

  • Setting: gamecraft-agent.enableCodeActions

  • Default: Enabled

  • Purpose: Controls whether Gamecraft Agent quick fix options appear in the editor interface

To modify this setting:

  1. Open Gamecraft Settings (Ctrl/Cmd + ,)

  2. Search for "enableCodeActions"

  3. Toggle the checkbox to enable or disable the feature

Last updated