Write Text To A File In VS Code With An Extension
This opens an untitled file with python syntax highlighting and write the string to it.
See also this popst which is what I want to do most of the time:
[issue: could not generate tlink]
extension.ts
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
const disposable = vscode.commands.registerCommand('vs-code-auto-typer.autoTypeScript', async () => {
const doc = await vscode.workspace.openTextDocument({ language: "python" });
await vscode.window.showTextDocument(doc, { preview: false });
const editor = await vscode.window.activeTextEditor;
const pos = new vscode.Position(0, 0);
if (editor) {
await editor.edit((editBuilder) => {
editBuilder.insert(
pos, `print("hello, extension")`
);
});
}
});
context.subscriptions.push(disposable);
}
export function deactivate() {}
-- end of line --