Generative AI Conversations

The Pieces for Visual Studio Extension provides flexible options for interacting with generative AI, enabling you to gain insights, debug, and optimize your code seamlessly within your editor.


Accessing Copilot Chat in VS Code

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

via Right-Click Menu

1

Highlight Code and Right-Click

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

2

Choose "Ask Copilot"

Choose an option from the list that best fits your use case:

  • Ask Copilot About Selection

  • Ask Copilot About Active File

  • Add Active File to Copilot Context

  • Explain Selection with Copilot

3

Enter Question

A new menu will pop up asking for your question, enter it, and enter

via Keyboard Shortcuts

You can also open up a dialogue with the Pieces Copilot—specifically the Ask Copilot option—by using the shortcut alt+m and then pressing a.

via Command Palette

Open the command palette with ctrl+shift+p, and enter commands, such as:

Pieces > Ask Copilot about Selection: Generates suggestions or improvements for the selected code snippet.

Pieces > Ask Copilot About Active File: Provides insights for the current file open in your Visual Studio editor.

Read more about what commands are available in the Pieces for Visual Studio Extension.

via AI Quick Actions

One quick way to get an explanation for a confusing or unclear function is by using the new AI Quick Actions feature in the Pieces for Visual Studio Extension.

Simply click the Pieces tool above a code function, then select Explain. This will start a conversation about the selected function.

You can also right-click a selected portion of code, hover over Pieces, and select Explain Selection with Copilot.

This action triggers the Copilot Chat window, which provides a detailed explanation and summary of the code's logic.

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

Contextualized Chats

There are two levels of contextual awareness in Visual Studio you can use when starting a conversation or adding code to an existing Copilot Chat with the Pieces Copilot.

Pieces > Ask Copilot About Selection

Use the Pieces > Ask Copilot About Selection button to interact with Copilot about specific code snippets, functions, or classes.

To use this feature:

1

Choose your Selection

Select a portion of code or select a class in the solution explorer.

2

Right-Click

Open the tool menu by right-clicking your selection

3

Locate “Ask Copilot About Selection”

Located the Pieces tool menu section, hover over it, and select Ask Copilot About Selection

4

Ask your Question

Type your prompt in the text input field and press enter

This approach is perfect for getting quick insights or guidance on specific code functionality.

Pieces > Ask Copilot About Active File

The Pieces > Ask About Active File feature targets the current file, providing specific insights and help with debugging.

There are two ways to access this command:

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

  2. Open the command palette using ctrl+shift+p and enter Pieces > Ask Copilot About Active File, then enter your query into the dropdown text input field.

After you enter your question, Pieces Copilot will analyze the file's context to provide precise responses.

This feature helps you understand file dependencies, methods, and structure. It also detects potential issues, suggests improvements, and more.

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

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 is especially useful when reference materials are not directly accessible from Visual Studio or when you want to compartmentalize context, minimizing overlap by keeping files or folders from other projects separate from your active workflow.

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

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

Adding Code Snippets

You can insert code snippets as a code block in any Copilot Chat by clicking the { } icon in the chat window and pasting your code.

This feature is particularly helpful for referencing code that isn't in the active file or for making comparisons and receiving tailored suggestions.

Extracting Code from Screenshots

You can extract code directly from screenshots through the Copilot Chat menu. Simply select Extract Code from Screenshot, choose the desired screenshot from your File Explorer, and confirm.

Pieces Copilot will scan the screenshot, generate the code from the image, and display it in the chat. From there, you can copy the code, insert it at your cursor, save it as a snippet, and more.

Adding Folders from File Explorer

You can add folders to your Copilot Chat context by clicking on the Starred Message Icon in the bottom-left corner of your Copilot Chat window, openable from the Visual Studio sidebar.

You can then choose which type of context you’d like to add, but in our case we’re going to choose folder.

This will open a new prompt that will guide you through the process of adding folders to context.

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