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

邮差的信 提交于 2020-01-15 05:32:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!