How to use Code Snippets in DVT IDE for VS Code
Overview
This video demonstrates how code snippets help you quickly deal with boilerplate code. It also covers creating custom snippets and modifying auto-generated code such as method stubs for overrides and implementations to match your coding style.
For snippet syntax details see: https://code.visualstudio.com/docs/editing/userdefinedsnippets
Details
Introduction
Code Snippets are templates that make it easier to insert repeatable code patterns.
You can see all available snippets in the content assist proposals list, where they are marked with distinctive icons. DVT IDE comes with a rich collection of built-in snippets ranging from assertions and simple for loops, to covergroups with all options and even entire test bench components.
Inserting code snippets
Type a few letters of the snippet name and pick a snippet from the proposals list.
You can see a preview of the snippet's content in the tooltip.
Press Enter to insert it and Tab to fill in the placeholders. Notice how the replacement is made for all occurrences of each placeholder at once.
You can also run the Insert Snippet command and use the dedicated picker.
By the way, note how you can seamlessly add fill-in instructions by instrumenting snippets with TODO tasks.
Creating new code snippets starting from DVT predefined ones
To match your own methodology and coding guidelines you can create new snippets starting from predefined ones using the Create New Snippet... command. For example, let's create a class snippet where we customize the name and comment.
For more information about the syntax, check the link in the video description.
Customize automatically generated code
Speaking of style and methodology, you can also change the way DVT generates code, for example when overriding virtual methods or when declaring the missing implementation stub of an extern method.
These code actions actually rely on predefined snippets that you can customize.
For example, let's take the method_implementation snippet, change the block comment and place the list of arguments on a new line.
Note how the customization takes effect.