我正在编写 VSCode 扩展,需要根据用户选择的文件夹/子文件夹创建文件/删除文件。
有没有办法通过 visual studio code api 从资源管理器树中找到选定的文件夹?可以通过事件文本编辑器或 onDidOpenTextDocument()
跟踪打开的文件。我有兴趣查找用户是否选择了一个文件夹,如果是,则查找所选文件夹的路径。
例如:workspace.rootPath
提供打开项目的根。同样,我如何识别用户选择了哪个子文件夹(如果有)。
最佳答案
我终于弄明白了,我一直在寻找一段时间,发现文档指出:
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
让我在 github 上解决这个问题/错误 Get selected file folder ,这反过来又把我带到了 github repo stef-levesque/vscode-hexdump我从中得到以下信息:
let disposable = Commands.registerCommand('extension.superExtension', async (fileUri) => {
console.log(fileUri);
})
注意:当在编辑器中使用上下文菜单时,这将为空。
关于typescript - 用于文件资源管理器的 vscode api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38270751/