home ~ projects ~ socials

Create An Untitled File In A VS Code Extension

This is the extension.ts file that opens a new, untitled file and brings it up in the editor.

(You'll need to change vs-code-auto-typer.autoTypeScript to match whatever you have in your package.json file)

See also this post which is what I want to do most of the time:

[issue: could not generate tlink]

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
	const disposable = vscode.commands.registerCommand('vs-code-auto-typer.autoTypeScript', async () => {
    /////////////////////////////////////////////////////
    // Basic open of an untitled file:
		const doc = await vscode.workspace.openTextDocument();
    // you can also add a language to openTextDocument to set up
    // for specific syntax highlighting. For example:
    //
    // const doc = await vscode.workspace.openTextDocument({ language: "python" });
    /////////////////////////////////////////////////////
		await vscode.window.showTextDocument(doc, { preview: false });
	});
	context.subscriptions.push(disposable);
}

export function deactivate() {}
-- end of line --

References