Code actions

Code actions provide quick fixes, refactorings, and AI-powered suggestions directly in your editor. When you select code or encounter a problem, Bob offers contextual assistance through a lightbulb icon or context menu.

Why use code actions?

  • Quick access to Bob: Add code to your conversation without copying and pasting
  • Contextual assistance: Get help with the exact code you are working on
  • Streamlined workflow: Access Bob's capabilities without leaving your editor
  • Automatic context: Bob receives file paths and line numbers automatically

How it works

Code actions appear when you:

  • Select a range of code
  • Place your cursor on a line with a diagnostic (error, warning, or hint)
  • Invoke them through a keyboard shortcut or command

A lightbulb icon () appears in the editor gutter (the area to the left of line numbers) when code actions are available. You can also access them through the right-click context menu or keyboard shortcut (Ctrl + . or Cmd + . on macOS).

Available code actions

Bob provides these code actions:

ActionDescriptionPosition in menu
Add to ContextAdds selected code to your Bob conversation with file path and line numbersFirst (for quick access)
Explain CodeAsks Bob to explain the selected codeSecond
Improve CodeAsks Bob to suggest improvements to the selected codeThird
Inline ChatOpens an inline chat interface directly in the editor at the cursor position for quick interactionsFourth
Move to ChatSends the selected code to the Bob chat panel with contextFifth

Add to Context

The Add to Context action appears first in the menu for quick access. When you use it, Bob includes the filename and line numbers with your code, helping Bob understand the exact location within your project.

Example of what Bob receives:

Can you explain this function?
@myFile.js:15:25

The @myFile.js:15:25 notation represents the code you added, including its location.

Inline Chat

The Inline Chat action opens a chat interface directly in your editor at the cursor position, allowing you to interact with Bob without switching to the chat panel. This is useful for quick questions or edits while staying focused on your code.

How to use:

  1. Select the code you want to discuss or place your cursor where you want to chat.
  2. Trigger the Inline Chat action through the lightbulb menu, context menu, or keyboard shortcut (default: Cmd + K on macOS, Ctrl + K on Windows/Linux).
  3. Type your question or request in the inline chat interface.
  4. Bob responds directly in the editor, and you can accept, reject, or modify the suggestions.

Move to Chat

The Move to Chat action sends your selected code to the Bob chat panel with full context, including file path and line numbers. This is ideal when you want to have a more detailed conversation about the code in the main chat interface.

How to use:

  1. Select the code you want to discuss.
  2. Trigger the Move to Chat action through the lightbulb menu, context menu, or keyboard shortcut (default: Cmd + L on macOS, Ctrl + L on Windows/Linux).
  3. The selected code is automatically added to the chat panel with context.
  4. Continue the conversation in the chat panel with Bob.

Using code actions

You can access Bob's code actions in three ways:

From the lightbulb icon

  1. Select the code you want to work with.
  2. Click the lightbulb icon () that appears in the gutter.
  3. Select the Bob action you want from the menu.
  4. Review Bob's response in the chat panel.

From the context menu

  1. Select the code you want to work with.
  2. Right-click the selected code.
  3. Select Bob from the context menu.
  4. Select the action you want from the submenu.
  5. Review Bob's response in the chat panel.

From the Command Palette

  1. Select the code you want to work with.
  2. Open the Command Palette with Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  3. Type "Bob" to filter commands.
  4. Select the code action you want (for example, "Bob: Explain Code").
  5. Review Bob's response in the chat panel.

Bob's tip: The Command Palette applies actions to your current active chat task if one exists.

How is this topic?