Announcement
· Jun 29, 2023

Share VS Code snippets as IPM / ZPM packages

VS Code has a powerful snippets capability, and its Marketplace offers a way for developers to publish their snippets so others can use them. However, publishing on Marketplace takes some effort and snippets targeting InterSystems coders will realistically only be of interest to a very small number of Marketplace visitors.

This inspired me to create oex-vscode-snippets-template, a GitHub template for creating repositories dedicated to publishing code snippets for InterSystems devs.

Also published on Open Exchange and installable using IPM / ZPM is a snippets example repository called oex-vscode-snippets-example. To install the package in a namespace:

zpm "install vscode-snippets-John.Murray-example"

Then next time you use the Server Manager and InterSystems ObjectScript extensions to edit server-side in that namespace the code-completion (Ctrl+Space) list will include several snippets for inserting TODO comments.

oex-vscode-snippets-template is my entry to the 2023 Grand Prix contest. If you like it please vote for it. Feedback also welcome.

Discussion (5)3
Log in or sign up to continue

Thanks @Evgeny Shvarov

Since Package Manager is server-centric this puts the package author's _OEX_*.code-snippets files on the filesystem of the IRIS server you install the package into. But if you also / instead want to use them for client-centric VS Code editing you can copy them somewhere else. There's a note about this at the end of the README.

To make the contents of a .code-snippets file available to all of your folders / workspaces, put it into the snippets subfolder of the folder that contains your settings.json file. One way to locate that folder is to run the command "Preferences: Open User Settings (JSON)", then use the context menu of its editor tab to reveal the file in Finder / File Explorer. You should see a snippets subfolder there.

Alternatively, use the "Snippets: Configure User Snippets" command, choose to create a new Global Snippets file, enter a name for it (file extension doesn't need to be entered), then paste the snippets into it.

It's is a bit dangerous saying "Package Manager is server-centric".

I never code with "server-centric" paradigm, but I always use Package manager. So I install all the necessary packages I need during the docker build procedure of my dev-environment with IRIS. E.g. like in this line:

zn "USER"
    zpm "install git-source-control"
    do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("SourceControl.Git.Extension")
    zpm "install passwordless"
    zpm "install objectscript-json-trace-viewer"

    zpm "load /home/irisowner/dev/ -dev -v":1:1
    halt

Can I use such an approach with snippets?