I have decide to try develop my own vs code extension
A code snippets for typescript/angular
I have my first snip Forloop.snippet
const ForLoopSnippet = 'for (let {{iterator}} = {{start}}; {{iterator}} <= {{end}}; {{iterator}} += {{step}}){//code}'
i have my extension.ts
import * as vscode from 'vscode';
import * as fs from 'fs';
const forLoopSnippetFilePath = vscode.Uri.file('../Src/typescript/Forloop.snippet');
const forLoopSnippet = fs.readFileSync(forLoopSnippetFilePath.fsPath, 'utf8');
export function activate(context: vscode.ExtensionContext) {
console.log("Activating for loop snippet")
let disposable = vscode.commands.registerCommand('extension.insertForLoopSnippet', () => {
const editor = vscode.window.activeTextEditor;
if (editor) {
editor.insertSnippet(new vscode.SnippetString(forLoopSnippet));
console.log("inserted")
}
});
context.subscriptions.push(disposable);
}
export function deactivate() {}
and my package.json
{
"name": "angulartypescriptexctention",
"version": "1.0.0",
"description": "",
"main": "./Src/extension.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"vscode": "^1.1.37"
},
"devDependencies": {
"@types/node": "^20.12.7"
},
"contributes": {
"keybindings": [
{
"command": "extension.insertForLoopSnippet",
"key": "ctrl+shift+f",
"mac": "cmd+shift+f",
"when": "editorTextFocus"
}
]
}
}
i have ran the extension and according to thew logs it gets activated but the snip never pops up
i have tried lots of key combos (ctrl+shift+f, ctrl+shift+l,ctrl+shift+q,ctrl+shift+o, Ect.)
also tried calling it with ctrl+shift+p and look for insertForLoopSnippet
but it isn't there
considering I'm new to this I'm probably just overlooking something
Some times is says activating extension but nothing happens