Quicker way to create a new file (that looks like the current one).
Hit ctrl+shift+N to create a new file that has the same context as the current one:
- Same extension and directory
- Same package declaration (where applicable)
- Same imports
- Same hashbang (
#!) string (also,chmod +x) - Boilerplate code (where applicable)
- Go (Package, imports and build constraints)
- Java (Package, imports and
classboilerplate) - PHP (
<?php) - Python (Imports)
- Shellscript (
setandsourcestatement)
Other extensions can now provide their own "New File" template/generator - useful for project-specific conventions.
To extend, add something like this to your extension:
export async function register(context: vscode.ExtensionContext) {
const ext = vscode.extensions.getExtension('avive.quick-new-file');
if (!ext) {
return;
}
let api = await ext.activate();
maker1 = {
createNewContent(runner) {
return "new body goes here";
}
}
provider = {
maker(reference: vscode.TextDocument) {
return maker1;
}
order() { return 666; }
}
api.registerFileMakerProvider(provider);
}The src/definitions/quick-new-file.d.ts file has more precise definitions.