问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/51146291/is-it-possible-to-write-a-plugin-to-open-a-directory-and-generate-some-files-in