vscode icon indicating copy to clipboard operation
vscode copied to clipboard

`vscode.openFolder` command does not reuse window even using `forceReuseWindow` or `forceNewWindow` options

Open mdaloia opened this issue 4 months ago • 0 comments

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.94.2
  • OS Version: macOS (but not OS specific I think)

It is not possible to open a folder with the built-in command vscode.openFolder and reuse the window. Even if there isn't anything open in the window (just one, totally empty, no folders/workspaces/editors/welcome), it closes the current window and creates a new one.

The vscode.openFolder built-in command documentation states that an options object could be supplied with the following options:

  • forceNewWindow: Whether to open the folder/workspace in a new window or the same. Defaults to opening in the same window.
  • forceReuseWindow: Whether to force opening the folder/workspace in the same window. Defaults to false.

Developing an simple extension and using any of the below statements ends up closing the window and opening a new one:

vscode.commands.executeCommand('vscode.openFolder', undefined);  // undefined to show folder picker, no options = Defaults to opening in the same window
vscode.commands.executeCommand('vscode.openFolder', undefined, { forceNewWindow: false } );
vscode.commands.executeCommand('vscode.openFolder', undefined, { forceReuseWindow: true } );
vscode.commands.executeCommand('vscode.openFolder', undefined, { forceNewWindow: false, forceReuseWindow: true } );

The implication of this window re-creation is that all extensions are reloaded.

Here is a short demo:

https://github.com/user-attachments/assets/030aa5fa-2b21-4c35-901a-0c38da561ec2

This happens even with for example the Git integration internal extension as shown in the below "Step to Reproduce".

Steps to Reproduce:

  1. Open VS Code (only one window, totally empty, no folders, workspaces, editors, welcome).
  2. In Explorer, hit button "Clone Repository".
  3. Provide a local or remote GIT repository.
  4. Select a destination folder for the cloned repository.
  5. By default it will ask to Open (in the same window), Open in New Window or Cancel ... Select Open
  6. Current window is closed, extensions deactivated, new window is created and extensions are re-started.

This is the code that handles this behavior on the Git extension: https://github.com/microsoft/vscode/blob/759c92ba74b1d536bd1e023d6581812845334fc2/extensions/git/src/commands.ts#L899-L905

By the way, as part of the analysis I found out some undocumented options for vscode.openFolder: https://github.com/microsoft/vscode/blob/759c92ba74b1d536bd1e023d6581812845334fc2/src/vs/workbench/browser/actions/workspaceCommands.ts#L156-L221

mdaloia avatar Oct 18 '24 21:10 mdaloia