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

Ahona DasAhona DasSenior Technical Content Writer
Building a VS Code Extension to Generate Snippets

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

Visual Studio Code (VS Code) supports global snippets, which are pre-defined pieces of code that help streamline the coding process. For instance, typing "log" in VS Code suggests a snippet to log output to the console. Similarly, snippets exist for common operations like foreach. These can significantly simplify development tasks.

You can also create your own snippets manually. Here’s a quick guide:

  1. Press Command+Shift+P and type "snippets".
  2. Select your programming language to open a file where you can write your snippet in JSON format.
  3. Define your snippet with a prefix, body, and description.


Limitations of Manual Snippets

While manually adding snippets is helpful, it has its limitations:

  • 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

To address these challenges, building a VS Code extension to generate snippets is a robust solution. Here’s how to get started:

1. Install Yeoman and the VS Code Extension Generator:

npm install -g yo generator-code

2. Run the Yeoman generator: Follow the prompts to create a basic boilerplate for your extension:

yo code

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

Following are the steps to be followed to add snippets and publish a vscode extension:

  1. Set Up Snippets Directory:
    • Create a snippets directory in your extension folder.
    • Add a language-specific JSON file (e.g., javascript.json) in the snippets directory.
  2. Define Snippets:


Automating Snippet Generation

Manual snippet creation is tedious, especially with numerous components. We, at Gluestack leverages Storybook for generating snippets automatically:

  1. Use Storybook as Source:
    • Each component and its variations are documented in Storybook.
  2. 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

Once the extension is ready, publishing it to the VS Code Marketplace involves:

1. Build the Extension:

vsce build

2. Publish 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:
vsce login

Publish the extension:

vsce publish
Hire Us Form


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

RELATED ARTICLES

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari
The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari
A real-world look at how oversized images can trigger Safari reloads and iOS crashes in Flutter apps and how smarter image decoding prevents them.
From Prompting to Process: What Changed When Flutter Shipped Agent Skills
From Prompting to Process: What Changed When Flutter Shipped Agent Skills
This blog explores how Flutter Agent Skills improve AI-assisted development by combining official framework workflows with project-specific guidance for more consistent development.
Why Everything Your AI Builds Looks the Same
Why Everything Your AI Builds Looks the Same
This blog explores why AI-generated interfaces often look alike and explains how design systems, product context, and reusable engineering practices help teams build distinctive, scalable
How We Built the Missing Bridge from Code to Figma
Technology

Jul 10, 2026

How We Built the Missing Bridge from Code to Figma
This blog explores how AI-generated React apps get turned into fully editable, designer-ready Figma files by reading React Fiber instead of the DOM.
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability
Technology

Jun 27, 2026

Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability
A practical breakdown of building resilient AWS-to-on-premises connectivity with WireGuard HA, active-standby failover, and deep packet-forwarding observability.
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
Technology

Jun 19, 2026

We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
A practical guide to building a 114-second multi-cloud disaster recovery failover between AWS and Azure — what we built, what broke, and what we learned.
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
Technology

Jun 12, 2026

Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
This blog explains how organizations can balance speed, scalability, and operational flexibility as they grow from startup to enterprise scale.

The Right Conversation Can Save You Six Months.

Whether you’re navigating AI adoption, modernizing legacy systems, or scaling a product - we start by listening. No pitch deck. No template. A real conversation.