[英]VSCode: opening a folder and a file from the same routine
作为同一操作的一部分,从扩展名打开文件夹和文件的正确方法是什么?
看起来很简单,但是我花了很多时间无法解决它。 我可以轻松地做一个或另一个,但不能同时做一个。
commands.executeCommand('vscode.openFolder',
Uri.parse('E:\\dev\\proj'))
.then(() => commands.executeCommand('vscode.open',
Uri.file('E:\\dev\\files\\file.json'));
上面的代码打开一个文件夹,但没有打开文件。 从调试器中,我看到vscode.open
命令被触发但文件未打开。 而使用'vscode.open'仅按预期方式打开文件。
似乎在打开文件夹后,整个执行上下文都消失了。
我做了这个残酷的实验:
setTimeout(() => commands.executeCommand('vscode.open',
Uri.file('E:\\dev\\files\\file.json'), 3000);
commands.executeCommand('vscode.openFolder',
Uri.parse('E:\\dev\\proj'))
而且它vscode.openFolder
如果调用vscode.openFolder
则永远不会调用setTimeout的回调。
将不胜感激任何帮助/提示。
我找到了问题的原因。 但不是解决方案。
显然打开文件夹会完全终止执行上下文。 这就是VSCode文档所说的:
Note that opening in the same window will shutdown the current extension host process and start a new one on the given folder unless the newWindow parameter is set to true.
因此,当前似乎无法在当前窗口中打开已打开并处于活动状态的特定文件的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.