How to create a VS Code extension

Search for a command to run...

No comments yet. Be the first to comment.
Twitter is one of the most popular social media platforms in the world, with over 330 million active users as of 2021. If you are interested in building a Twitter-like application, this tutorial will guide you through the process of building a FullSt...

Hey everyone, In this article, we will build our own Tic Tac Toe game using pure Javascript. https://youtu.be/lKe57l8sttw Code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE...

Hi everyone, In this blog, we will learn how we can create node.js functions locally and deploy them to AWS Lambda using serverless. So, let's get started. Step 1. Create an AWS Account ☁️ In order to deploy functions to AWS Lambda, you should have a...

Hey there, In this article, we are going to learn how you can upload any file to firebase storage. Uploading files to firebase storage is really easy. I would I recommend you to code along with me for better understanding. So, let's get started. Step...

Hey there, Welcome back. In this article, I would be showing you how I made a collaborative IDE with a video call. The main application of this application is that you can create a room and people can join the room. You have the ability to write mark...

Hi there, in this article we would be creating an extension for VS Code and publishing it to the vscode marketplace.
We would be building an auto-complete extension that auto-completes the bootstrap snippets in an Html file.
You must have node.js installed on your machine.
Yes, you read that correctly. We have to install yo to create our vscode extension.
To install yo fire-up your terminal or command prompt.
Note: Windows users please open your command prompt as an administrator.
After being set type in the following command:
sudo npm install -g yo
npm install -g yo
Setting up the project is really simple.
All you need to do is:
Create a new folder. Let us say “myFirstExtension”
Open your terminal or command prompt and navigate to the folder we have just created.
Run the following command
yo code

After that being done, you would be prompted with some questions such as the name of the extension, description etc.
“Enter the language for which the snippets should appear. The id is an identifier and is a single, lower-case name such as ‘PHP’, ‘javascript”
Type in html for this as we are creating snippets for HTML

Now you may close your terminals and command prompts and open the folder we created in the previous step. There you will notice a folder created with the name of your extension. Open this folder inside your favourite code editor. Like vscode in my case.

At this point, your snippets.json file would we something like this
{}
Yep, it’s an empty object and we have to code our snippets inside this object.
Code along with me:
{
"start":{
"prefix": "!start",
"body": [
"<html>",
"</html"
],
"description": "Basic Starter Template"
}
}
prefix: what user would type to access the snippet
body: the body of the snippet. In this case Array of HTML tags
So whenever users types “!start” in vscode the body of our snippet would be printed there.
{
"start":{
"prefix": "!start",
"body": [
"<html>",
"</html"
],
"description": "Basic Starter Template"
},
"h1":{
"prefix": "!h1",
"body": [
"<h1>",
"</h1"
],
"description": "Basic html tag"
}
}
Just keep adding your snippets and create some great snippets.
Please post your extension links below because I cant wait to see what you have made.
https://gist.github.com/piyushgarg195/36fda82a1662e04618a34afbca293830
At this point, you have successfully created your vscode extension.
Now open package.json file present in your project folder.
{
"name": "bootstrap-snippets",
"displayName": "bootstrap-snippets",
"description": "A simple Bootstrap snippets",
"version": "0.0.1",
"engines": {
"vscode": "^1.44.0"
},
"categories": [
"Snippets"
],
"contributes": {
"snippets": [
{
"language": "html",
"path": "./snippets/snippets.json"
}
]
}
}
In this file, we need to make a few changes as listed below:
{
"name": "bootstrap-snippets",
"displayName": "bootstrap-snippets",
"description": "A simple Bootstrap snippets",
"publisher": "piyushgarg",
"version": "0.0.1",
"engines": {
"vscode": "^1.44.0"
},
"categories": [
"Snippets"
],
"contributes": {
"snippets": [
{
"language": "html",
"path": "./snippets/snippets.json"
}
]
}
}
This file is the documentation of your extension. You need to edit this file before publishing your extension.

To publish your extension first you need to download vse tool by writing a command
sudo npm install -g vsce
npm install -g vsce
vsce package
After this you would be prompted with a message saying
“A ‘repository’ field is missing from the ‘package.json’ manifest file. Do you want to continue? [y/N]”
This would create <extension_name>.vsix file

Head over to **https://marketplace.visualstudio.com/vscode **and create your free account.
After signing select publish extensions from the top right corner.

Note: Please make sure that the publisher name in package.json is same as you create a publisher here.



