Code Comments

With the Pieces Copilot inside the Pieces for VS Code Extension, you can quickly generate comments that capture the functionality and intent of your code—an often overlooked aspect of high-quality documentation.


Commenting Code Selections with Pieces Copilot

Pieces Copilot can analyze and comment on any selected portion of your code, explaining its logic line by line to help make sure your code is not only readable but also easy to understand for others.

via Right-Click Menu

To add comments to your code from the toolbar, select the desired lines, right-click, hover over Pieces, and choose Comment Selection with Copilot.

Pieces Copilot will then generate clear, contextual comments for the selected code right inside the Copilot Chat window.

You can then click Insert at Cursor to insert the fix at your cursors location. You can also click Accept Changes to place the code comments directly between your lines of code at precisely the location you selected the code from.

via Pieces: Comment

A quicker way of adding documentation to a function you may have previously overlooked is to click the Pieces: Add Comments tool, which appears above actionable functions in your code that are visible on your screen.

This new AI Quick Actions feature—similar to CodeLens actions that sit above functions nearest your cursor—can generate quick, insertable comments to explain the purpose and logic of your code.

To get started, look for the AI Quick Actions buttons above individual functions in your code.

Once you’ve located the AI Quick Actions, left-click on Pieces: Comment, then click Accept Changes to insert the newly commented code in the original code’s location.

Why Use Code Comments?

Code comments play a vital role in maintaining a clean, well-documented codebase.

They provide context for reviewers to focus on functionality and make complex reasoning transparent, ensuring code is easier to follow and maintain.

Good documentation improves code readability and accelerates onboarding for people unfamiliar with the codebase. This is a twofold benefit—it supports both current and future development, and creates a strong foundation for upgrading and reiterating.

Comments help you remember the purpose and function of the code, making it easier to revisit and understand after a long time away.

That’s why this specific feature is so powerful. Need a few hundred lines of code documented? No problem—just Comment Selection with Copilot.

Updated on