Generative AI Conversations

The Pieces for VS Code Extension offers flexible options for interacting with generative AI to gain insights, debug, and optimize code directly within your editor.


Accessing Copilot Chat in VS Code

There are two primary ways to access generative AI conversations with the Pieces Copilot.

via Right-Click Menu

  1. Highlight any code segment and right-click to open the tool menu

  2. Choose Ask Copilot About Selection, Ask Copilot About Active File, Add Active File to Copilot Context, or Explain Selection with Copilot from the tool menu depending on your use case

via Keyboard Shortcuts

You can also open up a dialogue with the Pieces Copilot—specifically the Ask Copilot About Selection option—by using the shortcut ⌘+shift+a (macOS) or ctrl+shift+a (Windows/Linux).

via Command Palette

Open the command palette with ⌘+shift+p (macOS) or ctrl+shift+p (Windows/Linux), and enter commands such as:

  • Pieces: Ask Copilot About Active File: Provides insights for the current file open in your VS Code editor.

  • Pieces: Ask Copilot About Selection: Generates suggestions or improvements for the selected code snippet.

  • Pieces: Ask Copilot About Workspace: Offers context-aware assistance across your entire workspace.

Read more about what commands are available in the Pieces for VS Code Extension.

via AI Quick Actions

One quick way of getting an explanation for a confusing or misremembered function’s logic is to use the new AI Quick Actions feature in the Pieces for VS Code Extension.

Try using the Pieces: Explain tool above your code to start a conversation about a particular function.

This triggers the Copilot Chat window which outputs an explanation and summary of the code function.

There is also Pieces: Comment, which you can read more about here.

Contextualized Chats

There are 3 different levels of contextual awareness that you can utilize when initiating a conversation (or adding code to an existing Copilot Chat) with the Pieces Copilot.

Pieces: Ask Copilot About Selection

Using the Pieces: Ask Copilot About Selection command lets you interact with Copilot regarding specific code snippets, functions, or classes.

To use this feature:

  1. Select a portion of code

  2. Open the command palette using ⌘+shift+p (macOS) or ctrl+shift+p (Windows/Linux) and type, then run the Pieces: Ask Copilot About Selection command

  3. Type your prompt in the text inout field and press return (macOS) or enter (Windows/Linux)

This approach is ideal for localized queries where you need quick insights or guidance on specific code functionality.

Pieces: Ask About Active File

The Pieces: Ask About Active File feature focuses on the current file, offering tailored insights and assistance with debugging.

There are two ways to access this command:

  1. Right-click inside your file and select the Ask Copilot about Active File, then enter your query into the dropdown text input field

  2. Open the command palette using ⌘+shift+p (macOS) or ctrl+shift+p (Windows/Linux) and enter Pieces: Ask About Active File

Once you've entered your question, the Pieces Copilot will analyze the file's context to deliver precise responses.

This feature is useful for gaining a better understanding of file dependencies, methods, and structure as well as detecting potential issues, suggesting improvements, and more.

The Pieces: Ask About Active File feature can also be applied during onboarding purposes to get helpful explanations for unfamiliar code.

Pieces: Ask Copilot About Workspace

With the Pieces: Ask Copilot About Workspace command, you can extend the Pieces Copilot’s assistance to fit the entire project scope.

To use this command:

  1. Open the command palette ⌘+shift+p (macOS) or ctrl+shift+p (Windows/Linux)

  2. Enter Pieces: Ask Copilot About Workspace and type your question

This is ideal for large projects where a project-wide perspective is needed, specifically for Identifying inconsistencies in naming conventions across multiple files, in error handling, or resolving global code redundancies.

Adding Context to Copilot Chats

There are a number of individual items you can add as context to a chat, namely Files, Folders, Snippets, Websites, and Messages.

This flexibility comes in handy when items you want to serve as reference material is not directly accessible from VS Code, or if you want to compartmentalize context and minimize overlap by keeping files or folders from other projects separate from your active file’s workflow.

To do this, you can select the Starred Message Icon in the bottom-left corner of your Copilot Chat window, openable from the VS Code sidebar.

Click the Starred Message Icon then add whatever context items you need.

Adding Code Snippets

You can paste snippets of code as a code block inside of any Copilot Chat by clicking the { } icon inside the chat window, then pasting in your code.

This is useful for bringing in code that isn’t present immediately in the active file as context, or for comparisons and suggestions.

Extracting Code from Screenshots

You can also extract code from screenshots directly from the Copilot chat menu by selecting Extract Code from Screenshot, selecting the desired screenshot from your Finder (macOS) or File Explorer (Windows/Linux) menu, and confirming.

Pieces Copilot will then scan the screenshot and generate the code captured from the image into the chat, from which you can copy, insert at your cursor, save it as a snippet, and more.

Adding Folders from File Explorer

If you right-click on a folder in your file explorer in VS Code, you’ll see 3 options: Pieces: Add to Copilot Context, Pieces: Ask Copilot and Pieces: Save File to Pieces, so you can take any folder in the project you’re working in and immediately have the Pieces Copilot interact with it.

Improving Code Consistency & Standardization

The Pieces Copilot helps improve code quality by identifying inconsistencies and providing actionable suggestions for standardization.

Naming Inconsistencies

If functions across your workspace use inconsistent naming patterns (e.g., authenticateUser in authHandler.go vs. retrieveUserProfile in userHandler.go), Pieces Copilot can suggest adopting a standardized naming convention for better readability and maintainability, like this:

// authHandler.go
func authenticateUser(ctx context.Context, credentials Credentials) (User, error) {
    if credentials.Username == "" || credentials.Password == "" {
        return User{}, errors.New("missing credentials")
    }
}

Inconsistent Error Handling

If error-handling strategies differ across files (e.g., structured errors in authService.go vs. inconsistent handling in userService.go), Pieces Copilot can help unify the approach:

// authService.go
func LoginUser(credentials Credentials) (string, error) {
    token, err := authenticate(credentials)
    if err != nil {
        return "", fmt.Errorf("login failed: %w", err)
    }
    return token, nil
}
Updated on