Create A Temporary ReadOnly File With A VS Code Extension
This is the code I'm using in extension.ts
NOTE: This is not what I generally want to do since it creates a virutal read-only file that you can't edit, but it was the first thing I figured out.
Probably you want:
[issue: could not generate tlink]
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
const myScheme = "autotyper";
const myProvider = new (class implements vscode.TextDocumentContentProvider {
provideTextDocumentContent(uri: vscode.Uri): string {
return "this is the initial content";
}
})();
context.subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider(myScheme, myProvider)
);
const disposable = vscode.commands.registerCommand('vs-code-auto-typer.autoTypeScript', async () => {
const uri = vscode.Uri.parse('autotyper:example-name');
const doc = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(doc, { preview: false });
});
context.subscriptions.push(disposable);
}
export function deactivate() {}
Notes
-
This is after making a new project with:
npx --package yo --package generator-code -- yo code
-- end of line --