Skip to main content

Save a Code Snippet and Have It Augmented With AI

Pieces allows you to save code snippets and automatically add context using AI. This helps you keep track of important code, make it easily searchable, and provide additional information like tags and relevant documentation links.

The generated context includes:

  • The programming language
  • A title for the code snippet
  • A set of generated tags
  • A description for what the code is doing
  • Suggestions for searches to learn more about the concepts in the snippet
  • Any people related to this snippet. This is found from the Git history if the file is in a Git repository

Prerequisites​

Before you begin, ensure you have:

Steps​

1. Find the code to save​

Inside an open file in Visual Studio Code, select the code block you want to save as a snippet.

A screenshot of VS Code with a Python function selected A screenshot of VS Code with a Python function selected

2. Save the Code Snippet​

Right-click on the selected code, and select Pieces -> Save Current Selection to Pieces.

A screenshot of VS Code with a Python function selected and the Pieces context menu showing A screenshot of VS Code with a Python function selected and the Pieces context menu showing

The snippet will be saved to Pieces. Pieces will automatically add context such as tags, links to documentation, information extracted from any Git history, and other relevant information.

3. Review the Enriched Snippet​

After Pieces has had a few seconds to process the snippet, review the snippet and the added context.

Select the Pieces Explorer from the Activity Bar. This will then show all the saved snippets, grouped by programming language.

A screenshot of the Pieces explorer in VS Code showing a python snippet A screenshot of the Pieces explorer in VS Code showing a python snippet

Select the new snippet to see the generated annotations.

A screenshot of a saved Python snippet with the code and associated context such as tags and a smart description A screenshot of a saved Python snippet with the code and associated context such as tags and a smart description

The generated enrichments include:

  • The programming language
  • A title for the code snippet
  • A set of generated tags
  • A description for what the code is doing
  • Suggestions for searches to learn more about the concepts in the snippet
  • Any people related to this snippet. This is found from the Git history if the file is in a Git repository

Next Steps​