Initial Release
InterSystems Tools and Utilities
The objective is to export User Defined Snippet Code from Studio to a JSON Format file that can be imported to VS Code User Defined Snippets.
The Code Snippets from Studio are exported as is, spaces indentation are exported as space, tabulation indentation are exported as tabulation.
Carriage Return are also exported. Make sure your Code Snippets are correct in Studio so that the JSON file will be correct too.
Studio 2020
Visual Studio Code
Either create a new class called Tools.CodeSnippets, copy and pass the content of the GitHub file Tools.CodeSnippets.cls and compile.
or import XML Tools.CodeSnippets.xml from GitHub source.
Open Studio
Go to Tools >> Options >> Environment >> Code Snippets
Check the User Defined Snippet Code path and file name (Click on Edit from the Code Snippet files you want to export)
Open Visual Studio Code
Go to File >> Preferences >> User Snippets
Select the snippets languages, i.e. objectscript (ObjectScript) language
Check the path and file name of the JSON files that should contains the Snippets.
The command line is :
do ##class(Tools.CodeSnippets).ConvertCodeSnippet(strINStudioFile, strINVSCodeJSONFile, strINLanguages)
the input parameters are not mandatory and can be empty:
Languages are:
Open a IRIS Terminal (or user Studio Output), and execute the command line.
Example to use with a prompt asking for the files paths and names call and export all snippets:
do ##class(Tools.CodeSnippets).ConvertCodeSnippet()
To use with the files path and names input as parameters call :
do ##class(Tools.CodeSnippets).ConvertCodeSnippet("C:\Users\jhuser\Documents\InterSystems\CodeSnippets.txt","C:\Users\jhuser\AppData\Roaming\Code\User\snippets\objectscript.json")
To use with the files path and names input as parameters call :
do ##class(Tools.CodeSnippets).ConvertCodeSnippet("C:\Users\jhuser\Documents\InterSystems\CodeSnippets2.txt","C:\Users\jhuser\AppData\Roaming\Code\User\snippets\java.json", "7,14")
Open Visual Studio Code and either check the content of JSON File within VS Code or try to type a snippet prefix.
Studio Code Snippets are saved in a Text File. Each Snippets are separated by an invisible character : $char(1)
Each Snippet contains : a Name separated with $char(2) from the language of the snippet separated with $char(2) with the content of the snippet’s code.
i.e. “Snippet Name” _ $char(2) _ “Snippet Language” _ $char(2) _ “Snippet Code Content” _ $char(1)
The VS Code JSON Snippet files required for each Snippet a Name and attributes : prefix, body, description (optional)
from studio only Name and Code content are available.
Description is set to the value of the Name.
Prefix is the value of the name with a conversion from alphaup to lower case.