简体   繁体   中英

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. And having 'vscode.open`only opens the file as expected.

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.

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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