May 22, 2024
Building a VS Code Extension to Generate Snippets
This blog breaks down the recent GeekSpeak talk presented by Meenu Makkar, SSE-1 at GeekyAnts, on building a VS Code extension to generate snippets.
Author


Book a call
Table of Contents
A common challenge in group projects, particularly when multiple developers work on the same codebase, is ensuring consistent coding styles. Another frequent issue is the need to search for frequently used APIs of the framework or library used. If these scenarios sound familiar, the solution presented here may be just what you need: building a VS Code extension to generate snippets.
The Power of Snippets in VS Code
foreach. These can significantly simplify development tasks.- Press
Command+Shift+Pand type "snippets". - Select your programming language to open a file where you can write your snippet in JSON format.
- Define your snippet with a prefix, body, and description.
Limitations of Manual Snippets
- Lack of dynamic variable support.
- Difficulty in handling complex languages.
- Poor shareability since each developer must manually update their snippets.
- No collaborative changes, requiring constant updates and sharing.
- Steep learning curve for new team members.
Building a VS Code Extension with Yeoman
2. Run the Yeoman generator: Follow the prompts to create a basic boilerplate for your extension:
3. Launch the extension development host instance: Press F5 in VS Code, which opens a new window for debugging the extension.
Adding Snippets to the Extension
- Set Up Snippets Directory:
- Create a
snippetsdirectory in your extension folder. - Add a language-specific JSON file (e.g.,
javascript.json) in thesnippetsdirectory.
- Create a
- Define Snippets:
- Include snippet definitions in the JSON file, specifying prefix, body, and description. For more info, check this for more info.
- Update
package.jsonto register these snippets under thecontributessection. Refer here: https://code.visualstudio.com/api/references/contribution-points
Automating Snippet Generation
- Use Storybook as Source:
- Each component and its variations are documented in Storybook.
- Scripted Snippet Generation:
- Write a script to parse Storybook stories through AST and generate the corresponding JSON snippets.
- This script handles fetching component names, bodies, and imports, streamlining the snippet creation process.
- Having a single source of truth for multiple things helps us reducing minor changes in the APIs.
Publishing the Extension
- Log in to your Azure Developer Dashboard and create an account.
- Generate a personal access token and use it to log in via the terminal:
Publish the extension:
Summing Up
By building a VS Code extension to generate snippets simplifies coding consistency and efficiency for developers. This automated approach ensures that all developers on a project use the same standards and reduces the learning curve for new team members. Embracing such tools can greatly enhance the development workflow and maintain high coding standards across teams.
Don’t miss out on the complete talk and presentation below ⬇️
Subscribe to Our Newsletter
Subscribe to RSS
Press & Media Hub RSS FeedRelated Articles.
More from the engineering frontline.
Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

Jun 27, 2026
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability

Jun 19, 2026
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned

Jun 12, 2026
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions

Jun 8, 2026
Geeklego: The Open-Source Design System Built to Work With AI

May 18, 2026
Your Vibe Code Has No Memory. DESIGN.md Fixes That.

May 14, 2026
