An example demonstrating how to implement a code snippet contribution using the VSCode code snippet framework.
A code snippet contribution is a VSCode extension which:
- Declares an
extensionDepedencytosaposs.code-snippet-tool:-
{ "extensionDependencies": ["saposs.code-snippet-tool"] }
-
- Returns an object from its
activate()method which defines the snippet's behavior (GUI form definition / code generation or edit actions).- TODO: define API's interface in TypeScript.
- Implements a trigger to use the code snippet.
- For example: a VSCode context menu command.
- Yarn >= 1.4.2
- A Long-Term Support version of node.js
- VSCode 1.39.2 or higher or Theia 0.12 or higher.
saposs.code-snippet(framework) extension installed in your VSCode instance.- Available on github releases.
In your terminal:
yarn(install/update dependencies)yarn compile
In your "root" VSCode instance:
FileMenu -->Open Folder--> .RunMenu -->Start Debugging.
This will open a new VSCode instance in which you should now:
FileMenu -->Open Folder--> <thedummy-scriptsfolder>.View-->Command Palette-->Create Launch Configuration.
This will open the snippet GUI in which you should now:
- For
Typedropdown --> choose "node". - For
Nameinput field --> enter "foo". - For
Programvalue --> use the file explorer to choose the hello-world.js. - Click the
CreateButton. - Approve the VSCode refactoring preview.
A launch.json file has now been created in the .vscode folder.
With the launch configuration you have defined.
You can now execute this launch configuration via the VSCode Run and Debug pane.