$1, $2, this is simply where the cursor ends up when you hit the tab button.description, this is a field that lets us describe a little more what is going on.The data type is an array and to support a snippet that has several rows we need to add a new entry to the array. prefix, this is what you need to type in the code window for the snippet to appear.ts file this snippet would be possible to use Each supported language is separated by a comma. scope, this is the supported languages for this snippet, supported languages here are javascript and typescript.Print to console defines an object within curly braces so let’s break down each property that it defines: This one is simply the name of the snippet. The next point of interest is Print to console. It is worth noting how everything starts with curly braces, and the reason for that is that we are simply editing a JSON file. Select the following from the menu Code /Preference / User Snippets Let’s head to the menu and create a global snippet. Our choice here is global vs language specific. The first thing we need to do is to select the type of snippet we are about to create. It’s almost dead easy to create a snippet so let’s do just that and explain concepts as we encounter them. language specific, only possible to use for a specific language.You can create two types of snippets in VS Code: What snippets you exactly need, is up to you. Your choice, you might have things you do quite often that’s unique to you - such as reading to/from a file, accessing a database, etc.Logging to the screen, we tend to do this quite often for the purpose of debugging.Function, we create a ton of functions, so some kind of default function with a suitable number of parameters make sense.Wouldn’t it be nice if there was a snippet that supported try, catch and finally? Try-catch, this is also a very common construct.If, we tend to write quite a lot of if, if else, if else if, else statements.Class, oftentimes we create plenty of classes in our solution.So what is a good candidate to make a snippet out of: We tend to use snippets someone else has created for us, or we create our own that fits our coding style. They are usually created to speed up our development work so we can spend time-solving interesting problems instead of typing the _same old_ _boring code_. Snippets are pieces of code that we can use again and again in our code projects. However, the article describes snippet creation in a general way so even if JavaScript or TypeScript isn’t your choice of language, you will hopefully understand how snippet creation works. This article is geared towards JavaScript and TypeScript so the code examples will be written in mentioned languages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |