This tutorial will walk you through adding a new command to the VS Code extension.
Let’s try adding a new command to foam-vscode
.
packages/foam-vscode/src/extension.ts
activate
functionexport function activate(context: ExtensionContext) {
context.subscriptions.push(
commands.registerCommand(
"foam-vscode.update-wikilinks",
updateReferenceList
),
+ commands.registerCommand(
+ "foam-vscode.hello-friend",
+ () => {
+ . window.showInformationMessage("Hello, friend!);
+ }
+ ),
workspace.onWillSaveTextDocument(onWillSave),
languages.registerCodeLensProvider(
mdDocSelector,
new WikilinkReferenceCodeLensProvider()
)
);
}
packages/foam-vscode/package.json
contributes.commands
array:"contributes": {
"commands": [
{
"command": "foam-vscode.update-wikilinks",
"title": "Foam: Update Markdown Reference List"
+ },
+ {
+ "command": "foam-vscode.hello-friend",
+ "title": "Foam: Hello Friend",
+ },
]
},
And that’s how you add new commands! We look forward to your contributions.
More resources:
How do I write a test for my extension addition?
This is still a work in progress. We’ve opted for Jest as our testing framework. There are currently no end-to-end tests (contributions are welcome!). However, we would encourage you to write tests for anything that you can test. We’re happy to discuss on PRs too!
How do I know if using the local version of the Foam extension vs. the produciton one while testing locally?
When you start the extension development host, the local version of the extension “shadows” or overrides any installed versions of the package with the same ID. So when you F5/start the extension host, you should always be running the local version, plus any other extensions your workspace/vscode is configured to run.
As far as we know, you can’t run the “shadowed” base install while running the local extension