Migrate SQLPrompt Snippets to VSCode

 I love snippets; love em. And I have a whole bunch in RedGate SQL Prompt. Now I want to be able to use those in VSCode as well, but boy do I dread having to retype all of them. Solution? Python! First arg is the path where your SQLPrompt snippets are Second arg is the directory where you want it to spit out a "sql.json" file with all your snippets. """ A script to translate sqlprompt snippet files to vscode formatted snippets """ import os import json import glob import io import argparse class SQLPromptPlaceholder :     """Represents the values of a SQLPrompt placeholder"""     def __init__ ( self , name , default_value ):         self . name = name         self . default_value = default_value class SQLPromptSnippet :     """Represents the content of a SQLPrompt snippet"""     @ staticmethod     def from_file ( filename ):         """Generates an instance fr

VSCode Snippet Template

 I'm a bit of a snippet junkie. You've heard of DRY in programming (Don't Repeat Yourself), well when I find I do something over and over again (e.g creating a table in sql, scaffolding a class in C#, or just "console.log(``)" in javascript), I quickly create a snippet for it to save time.

But this leads to a problem. I wind up doing the same thing over and over again; namely, creating snippets!.

Anyway, I created a snippet for creating snippets in VSCode. To use this

  1. Open the command palate (CTRL+SHIFT+P) 
  2. Select "Preferences: Configure User Snippets"
  3. Select "json.json (json)"
  4. Create the following snippet
{
    "Snippet Generator": {
        "prefix""snp",
        "body": [
            "\"$1\": {",
            "    \"prefix\"\"$2\",",
            "    \"body\": [",
            "        \"${3:$TM_SELECTED_TEXT}\"",
            "    ],",
            "    \"description\"\"${4:$1}\"",
            "},"
        ],
        "description""Generates a snippet stub"
    },
}
Now, any time you're in a JSON file (all snippet files are .json files) and you use the snippet "snp", you'll get a template for your snippet.



Comments

Popular posts from this blog

Migrate SQLPrompt Snippets to VSCode

Fixing Git "Unexpected Disconnect while reading sideband packet"

Left-Padding Zeroes