Building a VS Code Extension to Generate Snippets

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 Das
Ahona DasSenior Technical Content Writer

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

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization
Sep 23, 2026

Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization

Learn how legacy systems make business growth more expensive and how edge-first modernization can remove constraints without replacing the existing system.

Insight
SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam
Sep 23, 2026

SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam

Why AI-generated prototypes fail enterprise review: the context behind SSO, the cost of skipping audit logs, and how role explosion makes RBAC a product of its own.

Insight
Feature Flags as Technical Debt: The Cleanup Nobody Schedules
Sep 21, 2026

Feature Flags as Technical Debt: The Cleanup Nobody Schedules

This blog explains how unmanaged feature flags create technical debt and how teams can detect, manage, and remove them safely.

Insight
Building AI-First Enterprises: Why System Design Matters More Than AI Adoption
Sep 21, 2026

Building AI-First Enterprises: Why System Design Matters More Than AI Adoption

This blog explores how system design, architecture, and validation shape AI-first enterprises, while examining AI’s impact on software engineering and human decision-making.

Insight
The Product Studio in the AI Era: What Actually Changes | Sarika Gautam
Sep 21, 2026

The Product Studio in the AI Era: What Actually Changes | Sarika Gautam

What changes in product development when AI writes the code: the shift to architecture, the token cost of unplanned builds, and why juniors still matter.

Insight
AI and the Future of Digital Customer Experience: Where Technology Meets Human Creativity
Sep 18, 2026

AI and the Future of Digital Customer Experience: Where Technology Meets Human Creativity

A discussion on how AI, human creativity, research, and cross-functional collaboration are shaping the future of digital customer experience.

Insight
Scaling Down Before Scaling Up: Why Bigger Servers Don’t Fix Bad Architecture
Sep 17, 2026

Scaling Down Before Scaling Up: Why Bigger Servers Don’t Fix Bad Architecture

This blog explores how inefficient backend architecture can cause performance issues even under low traffic, covering practical ways to reduce database load, API latency, and resource usage before scaling infrastructure.

The Right Conversation Can

Save You Six Months.

Book a call