[英]vscode api for file explorer
I am onto writing a VSCode extension and need to create files / remove files based in a folder / subfolder selected by the user.我正在编写 VSCode 扩展,需要根据用户选择的文件夹/子文件夹创建文件/删除文件。
Is there a way to find selected folder from the explorer tree through visual studio code api?有没有办法通过visual studio code api从资源管理器树中找到选定的文件夹? One can track the opened file through active text editor or
onDidOpenTextDocument()
.可以通过活动文本编辑器或
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.例如:
workspace.rootPath
提供打开项目的根目录。 Similarly, how do I identify which subfolder is selected by the user (if any).同样,如何确定用户选择了哪个子文件夹(如果有)。
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.
注意:当从(上下文)菜单调用命令时,VS Code 会尝试推断当前选定的资源,并在调用命令时将其作为参数传递。 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.
例如,资源管理器中的菜单项被传递所选资源的 URI,而编辑器中的菜单项被传递文档的 URI。 vscode extension contribution points
vscode 扩展贡献点
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:这让我在 github 上找到了这个问题/错误Get selected file folder ,这又将我带到了stef-levesque/vscode-hexdump的 github 存储库, 从中我得到了以下信息:
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.注意:当在编辑器中使用上下文菜单时,这将是空的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.