typescript - 用于文件资源管理器的 vscode api

标签 typescript visual-studio-code vscode-extensions

我正在编写 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/

相关文章:

javascript - 重构多个方法使用的相似代码

JavaScript : copying data from one array of objects to another which has existing data gives incorrect result

typescript - 将数组传播到 typescript 中的参数

visual-studio-code - 如何在Visual Studio代码中更改注释的字体?

visual-studio-code - 是否可以在 VSCode 中以编程方式将文本文档设置为脏?

javascript - 如何在vscode扩展中打开本地(扩展包内)文件

javascript - VSCode 使用带有描述的快速选择列表项

typescript - 如何基于通用类型 "T"初始化 TypeORM 存储库?

debugging - vscode调试器配置: cwd

git - VSCode如何添加用于暂存选定行的键盘快捷键