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
Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15
Sep 10, 2026

Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15

This blog explains how to build a production-ready canvas editor with Konva.js, React, and Next.js, covering architecture, performance, and key engineering decisions.

Insight
What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust
Sep 8, 2026

What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust

This blog explores the architecture, security, performance, and documentation lessons from migrating a legacy PHP/Laravel banking platform to NestJS.

Insight
Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs
Sep 7, 2026

Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs

This blog explains how to build responsive video thumbnail scrubbing in the browser for local files and HLS streams, covering frame extraction, caching, and performance trade-offs.

Insight
The Agent Can See Your App. How Often Can It Look?
Sep 4, 2026

The Agent Can See Your App. How Often Can It Look?

AI coding agents can now interact with mobile apps, but their effectiveness depends on iteration speed. This blog explores how React Native architecture influences feedback loops and AI-driven developer productivity.

Insight
Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists
Sep 1, 2026

Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists

Learn how to turn design JSON into interactive, video-enabled cards using overlays, smart media controls, caching, and virtualization without slowing down high-cardinality feeds.

Insight
The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari
Aug 19, 2026

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.

Insight
From Prompting to Process: What Changed When Flutter Shipped Agent Skills
Aug 19, 2026

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.

The Right Conversation Can

Save You Six Months.

Book a call
GeekSpeak: Building VSCode Extension to Generate Snippets - GeekyAnts