Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mdaloia opened this issue Oct 18, 2024 · 3 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@mdaloia
Copy link

mdaloia commented Oct 18, 2024

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:

vscode-open-not-reuse-window.mp4

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:

if (action === PostCloneAction.Open) {
commands.executeCommand('vscode.openFolder', uri, { forceReuseWindow: true });
} else if (action === PostCloneAction.AddToWorkspace) {
workspace.updateWorkspaceFolders(workspace.workspaceFolders!.length, 0, { uri });
} else if (action === PostCloneAction.OpenNewWindow) {
commands.executeCommand('vscode.openFolder', uri, { forceNewWindow: true });
}

By the way, as part of the analysis I found out some undocumented options for vscode.openFolder:

interface IOpenFolderAPICommandOptions {
forceNewWindow?: boolean;
forceReuseWindow?: boolean;
noRecentEntry?: boolean;
forceLocalWindow?: boolean;
forceProfile?: string;
forceTempProfile?: boolean;
}
CommandsRegistry.registerCommand({
id: 'vscode.openFolder',
handler: (accessor: ServicesAccessor, uriComponents?: UriComponents, arg?: boolean | IOpenFolderAPICommandOptions) => {
const commandService = accessor.get(ICommandService);
// Be compatible to previous args by converting to options
if (typeof arg === 'boolean') {
arg = { forceNewWindow: arg };
}
// Without URI, ask to pick a folder or workspace to open
if (!uriComponents) {
const options: IPickAndOpenOptions = {
forceNewWindow: arg?.forceNewWindow
};
if (arg?.forceLocalWindow) {
options.remoteAuthority = null;
options.availableFileSystems = ['file'];
}
return commandService.executeCommand('_files.pickFolderAndOpen', options);
}
const uri = URI.from(uriComponents, true);
const options: IOpenWindowOptions = {
forceNewWindow: arg?.forceNewWindow,
forceReuseWindow: arg?.forceReuseWindow,
noRecentEntry: arg?.noRecentEntry,
remoteAuthority: arg?.forceLocalWindow ? null : undefined,
forceProfile: arg?.forceProfile,
forceTempProfile: arg?.forceTempProfile,
};
const uriToOpen: IWindowOpenable = (hasWorkspaceFileExtension(uri) || uri.scheme === Schemas.untitled) ? { workspaceUri: uri } : { folderUri: uri };
return commandService.executeCommand('_files.windowOpen', [uriToOpen], options);
},
metadata: {
description: 'Open a folder or workspace in the current window or new window depending on the newWindow argument. Note that opening in the same window will shutdown the current extension host process and start a new one on the given folder/workspace unless the newWindow parameter is set to true.',
args: [
{
name: 'uri', description: '(optional) Uri of the folder or workspace file to open. If not provided, a native dialog will ask the user for the folder',
constraint: (value: any) => value === undefined || value === null || value instanceof URI
},
{
name: 'options',
description: '(optional) Options. Object with the following properties: ' +
'`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. ' +
'`noRecentEntry`: Whether the opened URI will appear in the \'Open Recent\' list. Defaults to false. ' +
'Note, for backward compatibility, options can also be of type boolean, representing the `forceNewWindow` setting.',
constraint: (value: any) => value === undefined || typeof value === 'object' || typeof value === 'boolean'
}
]
}
});

@mdaloia
Copy link
Author

mdaloia commented Nov 6, 2024

@chrmarti apologies to bother you, but I want to confirm if this seems to be a bug or expected behavior. Thanks in advance

@chrmarti chrmarti assigned bpasero and unassigned chrmarti Dec 10, 2024
@bpasero
Copy link
Member

bpasero commented Dec 10, 2024

It is not possible to open a folder without restarting extensions. The setting is about reusing the current window or opening a second one.

See #69335

@bpasero bpasero added the info-needed Issue requires more information from poster label Dec 10, 2024
Copy link

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@vs-code-engineering vs-code-engineering bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants