vscode api for file explorer

自作多情 提交于 2021-02-05 05:57:05

问题


I am onto writing a VSCode extension and need to create files / remove files based in a folder / subfolder selected by the user.

Is there a way to find selected folder from the explorer tree through visual studio code api? One can track the opened file through active text editor or onDidOpenTextDocument(). I am interested in finding if user has selected a folder and if so the path to selected folder.

For example: workspace.rootPath provides a root of the opened project. Similarly, how do I identify which subfolder is selected by the user (if any).


回答1:


I finally figured it out, I've been looking for a while and found that the documentation states that :

Note: When a command is invoked from a (context) menu, VS Code tries to infer the currently selected resource and passes that as a parameter when invoking the command. For instance, a menu item inside the Explorer is passed the URI of the selected resource and a menu item inside an editor is passed the URI of the document. vscode extension contribution points

That let me to this question/bug on github Get selected file folder, which in turn led me to the github repo of stef-levesque/vscode-hexdump from which I got the following:

let disposable = Commands.registerCommand('extension.superExtension', async (fileUri) => {
    console.log(fileUri);
})

Note: when the context menu is used in the editor this will be empty.



来源:https://stackoverflow.com/questions/38270751/vscode-api-for-file-explorer

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