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
extensionDepedency
tosaposs.code-snippet
:-
{ "extensionDependencies": ["saposs.code-snippet"] }
-
- 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:
File
Menu -->Open Folder
--> .Run
Menu -->Start Debugging
.
This will open a new VSCode instance in which you should now:
File
Menu -->Open Folder
--> <thedummy-scripts
folder>.View
-->Command Palette
-->Create Launch Configuration
.
This will open the snippet GUI in which you should now:
- For
Type
dropdown --> choose "node". - For
Name
input field --> enter "foo". - For
Program
value --> use the file explorer to choose the hello-world.js. - Click the
Create
Button. - 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.