Adding your own snippets to VS Code

Primary tabs

One of the most useful features in Studio is code snippets.

Here's how to add snippets to VSCode.

Here's a generalized instructions.

1. Go to File - Preferences - User Snippets and choose objectscript.

2. Add your snippet, here's an example:

"SQL Statement": {
    "prefix": ["sql"],
    "body": ["#dim rs As %SQL.ISelectResult",
            "set rs = ##class(%SQL.Statement).%ExecDirect(,\"SELECT * FROM\")",
            "while rs.%Next() {",
            "\twrite rs.ID, !",

In here:

  • prefix - what you need to type for the snippet to appear
  • body - snippet body

Even better, snippets can include placeholders, for example:

"Method": {
    "prefix": ["method"],
    "body": ["set sc = ##class(${1:class}).${2:method}()"]

After you insert this snippet you're automatically moved to the start of the first placeholder, use <TAB> no iterate through the placeholders.

Happy coding!