简体   繁体   English

VSCode:从同一例程中打开文件夹和文件

[英]VSCode: opening a folder and a file from the same routine

What would be the right way of opening a folder and a file from an extension as a part of the same operation? 作为同一操作的一部分,从扩展名打开文件夹和文件的正确方法是什么?

Seems like a simple task but I spent quite some time and cannot solve it. 看起来很简单,但是我花了很多时间无法解决它。 I can easily do one or another but not both as a single operation. 我可以轻松地做一个或另一个,但不能同时做一个。

commands.executeCommand('vscode.openFolder', 
                        Uri.parse('E:\\dev\\proj'))
        .then(() => commands.executeCommand('vscode.open',
                                            Uri.file('E:\\dev\\files\\file.json'));

The code above opens a folder but not the file. 上面的代码打开一个文件夹,但没有打开文件。 From the debugger I see that vscode.open command is triggered but file is not opened. 从调试器中,我看到vscode.open命令被触发但文件未打开。 And having 'vscode.open`only opens the file as expected. 而使用'vscode.open'仅按预期方式打开文件。

It seems like after opening folder the whole execution context is gone. 似乎在打开文件夹后,整个执行上下文都消失了。

I did this brutal experiment: 我做了这个残酷的实验:

setTimeout(() => commands.executeCommand('vscode.open',
                                          Uri.file('E:\\dev\\files\\file.json'), 3000);
commands.executeCommand('vscode.openFolder', 
                        Uri.parse('E:\\dev\\proj'))

And it reviled that setTimeout's callback is never called if the vscode.openFolder is invoked. 而且它vscode.openFolder如果调用vscode.openFolder则永远不会调用setTimeout的回调。

Will appreciate any help/hint. 将不胜感激任何帮助/提示。

I found the cause of the problem. 我找到了问题的原因。 But not the solution. 但不是解决方案。

Apparently opening folder completely terminates the execution context. 显然打开文件夹会完全终止执行上下文。 This is what the VSCode documentation says: 这就是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.

Thus currently seems to be no way of opening in the current window a folder with a specific file opened and active. 因此,当前似乎无法在当前窗口中打开已打开并处于活动状态的特定文件的文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM