Zero
Zero

Reputation: 141

Is it possible to write a plugin to open a directory and generate some files in it?

I would love to write a plugin like yo plugin but with some UI. But yo could not work before you open a directory in vscode. What I need is to select a directory in my UI and automatically generate codes.

Can any one tell me which API to use to do such things and I will dig into it.

Upvotes: 2

Views: 330

Answers (1)

Gama11
Gama11

Reputation: 34138

You could use the showOpenDialog() method from the vscode.window namespace to let the user pick a directory if none is currently opened. With canSelectFiles: false and canSelectFolders: true, it turns into a folder picker. After that, you can run the "vscode.openFolder" command to open the newly created workspace.

vscode.window.showOpenDialog({
    canSelectFolders: true,
    canSelectFiles: false
}).then(folders => {
    if (folders != null && folders.length > 0) {
        setupProject(folders[0].fsPath);
        vscode.commands.executeCommand("vscode.openFolder", folders[0]);
    }
});

This is basically the approach we take for the "init project" command in the Haxe extension.

Upvotes: 3

Related Questions