Create or modify modules for this VS Code extension. Use when you see "create module", "new module", "add module", "modify module", "module template", "scaffold module". Provides templates from assets/templates/blank-module/ and handles JSONC package merging into package.json.
Quick start: Copy assets/templates/blank-module/ to create a new module in seconds.
Creates and modifies modules for this VS Code extension. Handles:
src/extension.tsTrigger keywords in user requests:
This extension uses a modular activation pattern where each module:
src/module-name/ directoryactivate{ModuleName} function.module-name-package.jsonc file with its configuration/commands/keybindingssrc/extension.ts in the main vsToys arraypackage.json during webpack buildThe webpack build process automatically merges all *-package.jsonc files from src/ into the main package.json:
In webpack.config.js:
// Finds all files matching pattern: src/**/.*-package.jsonc
const injectFiles = sync("src/**/.*-package.jsonc");
// Deep merges each file into package.json
for (const file of injectFiles) {
const injectContent = jsonc.parse(fs.readFileSync(file, "utf8"));
packageJson = merge(packageJson, injectContent);
}
Result: You define module features in isolated JSONC files, and they automatically appear in the final package.json during build.
Refer to the following documents for detailed information:
references/architecture.md - Complete overview of the module system, activation patterns, and extension lifecyclereferences/module-structure.md - Detailed breakdown of directory layout, file organization, and module anatomyreferences/jsonc-reference.md - Complete JSONC schema with all possible contribution typesreferences/quick-patterns.md - Common patterns for adding commands, keybindings, settings, and event handlerssrc/your-module-name/assets/templates/blank-module/ to your new module directory.blank-module-package.jsonc → .your-module-name-package.jsoncblank-module-main.ts → your-module-name-main.tsactivateBlankModule → activateYourModuleNamesrc/extension.ts in the vsToys arraynpm run compile to trigger JSONC mergingThe blank-module template in assets/templates/blank-module/ provides all the boilerplate you need—just copy it and customize!
All modules register via src/extension.ts:
const vsToys = [
{
name: "Copy Highlight", // Display name
moduleContext: "copy-highlight", // Used for config namespace & context keys
activator: activateCopyHighlight, // Function that runs on activate
deactivator: undefined // Optional cleanup
},
// ... more modules
];
Settings are automatically namespaced under vstoys.{moduleContext}.{setting}:
"vstoys.copy-highlight.enabled": { /* ... */ },
"vstoys.copy-highlight.backgroundColor": { /* ... */ }
Each module can set VS Code context keys for conditional keybindings:
// Sets context: vstoys.copy-highlight.active
vscode.commands.executeCommand("setContext", "vstoys.copy-highlight.active", true);
Each module gets its own output channel via the shared createOutputChannel helper:
import { createOutputChannel } from "../extension";
export function activateCopyHighlight(name: string, context: vscode.ExtensionContext) {
const print = createOutputChannel(name);
print("Module activating...");
}
Add to .module-name-package.jsonc:
"contributes": {
"commands": [
{
"command": "vstoys.module.commandName",
"category": "VsToys",
"title": "Module: Command Title"
}
],
"keybindings": [
{
"command": "vstoys.module.commandName",
"key": "ctrl+shift+x",
"when": "editorTextFocus && vstoys.module.active"
}
]
}
Register in main.ts:
context.subscriptions.push(
vscode.commands.registerCommand("vstoys.module.commandName", async () => {
// Implementation
})
);
Add to .module-name-package.jsonc:
"vstoys.module.settingName": {
"type": "string",
"default": "defaultValue",
"description": "What this setting does",
"order": 2000
}
Read in main.ts:
const config = vscode.workspace.getConfiguration("vstoys.module");
const value = config.get("settingName");
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("vstoys.module.settingName")) {
// Re-read and apply new settings
}
})
);
src/extension.ts loads and calls each module's activate functionvstoys.{module-context}.active is set to trueUse the assets/templates/blank-module/ as your starting point. It includes:
Copy these files, customize them for your module, and you're ready to implement!
When you run npm run compile:
webpack.config.jsmergePackageJSON() function runs immediately*-package.jsonc files under src/jsonc library)package.json in memorypackage.json back to diskImportant: The package.json is temporarily modified during build but should remain in version control with only the "base" configuration (no merged contributions).
.*-package.jsonc (leading dot!)setContext("vstoys.module.context", boolean)context.subscriptions for proper cleanupvscode.workspace.getConfiguration("vstoys.module")src/
├── extension.ts # Main entry, module registration
├── module-name/
│ ├── main.ts # Module implementation (exports activateModuleName)
│ ├── .module-name-package.jsonc # Configuration, commands, keybindings
│ └── [other supporting files]
└── [other modules...]
references/architecture.md for deep understandingreferences/jsonc-reference.md for all available optionsassets/examples/copy-highlight-annotated/ for a real working examplereferences/quick-patterns.md for specific implementation patterns