Skip to content

Commit af66efe

Browse files
authored
Ability to programmatically assign documents to open in a workspace before it's opened (fix microsoft#251202) (microsoft#251229)
1 parent 080c694 commit af66efe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/vs/workbench/browser/actions/workspaceCommands.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ILanguageService } from '../../../editor/common/languages/language.js';
2020
import { IFileDialogService, IPickAndOpenOptions } from '../../../platform/dialogs/common/dialogs.js';
2121
import { URI, UriComponents } from '../../../base/common/uri.js';
2222
import { Schemas } from '../../../base/common/network.js';
23-
import { IOpenEmptyWindowOptions, IOpenWindowOptions, IWindowOpenable } from '../../../platform/window/common/window.js';
23+
import { IFileToOpen, IFolderToOpen, IOpenEmptyWindowOptions, IOpenWindowOptions, IWorkspaceToOpen } from '../../../platform/window/common/window.js';
2424
import { IRecent, IWorkspacesService } from '../../../platform/workspaces/common/workspaces.js';
2525
import { IPathService } from '../../services/path/common/pathService.js';
2626
import { ILocalizedString } from '../../../platform/action/common/action.js';
@@ -160,6 +160,7 @@ interface IOpenFolderAPICommandOptions {
160160
forceLocalWindow?: boolean;
161161
forceProfile?: string;
162162
forceTempProfile?: boolean;
163+
filesToOpen?: UriComponents[];
163164
}
164165

165166
CommandsRegistry.registerCommand({
@@ -197,8 +198,9 @@ CommandsRegistry.registerCommand({
197198
forceTempProfile: arg?.forceTempProfile,
198199
};
199200

200-
const uriToOpen: IWindowOpenable = (hasWorkspaceFileExtension(uri) || uri.scheme === Schemas.untitled) ? { workspaceUri: uri } : { folderUri: uri };
201-
return commandService.executeCommand('_files.windowOpen', [uriToOpen], options);
201+
const workspaceToOpen: IWorkspaceToOpen | IFolderToOpen = (hasWorkspaceFileExtension(uri) || uri.scheme === Schemas.untitled) ? { workspaceUri: uri } : { folderUri: uri };
202+
const filesToOpen: IFileToOpen[] = typeof arg === 'object' ? arg.filesToOpen?.map(file => ({ fileUri: URI.from(file, true) })) ?? [] : [];
203+
return commandService.executeCommand('_files.windowOpen', [workspaceToOpen, ...filesToOpen], options);
202204
},
203205
metadata: {
204206
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.',
@@ -213,6 +215,10 @@ CommandsRegistry.registerCommand({
213215
'`forceNewWindow`: Whether to open the folder/workspace in a new window or the same. Defaults to opening in the same window. ' +
214216
'`forceReuseWindow`: Whether to force opening the folder/workspace in the same window. Defaults to false. ' +
215217
'`noRecentEntry`: Whether the opened URI will appear in the \'Open Recent\' list. Defaults to false. ' +
218+
'`forceLocalWindow`: Whether to force opening the folder/workspace in a local window. Defaults to false. ' +
219+
'`forceProfile`: The profile to use when opening the folder/workspace. Defaults to the current profile. ' +
220+
'`forceTempProfile`: Whether to use a temporary profile when opening the folder/workspace. Defaults to false. ' +
221+
'`filesToOpen`: An array of files to open in the new window. Defaults to an empty array. ' +
216222
'Note, for backward compatibility, options can also be of type boolean, representing the `forceNewWindow` setting.',
217223
constraint: (value: any) => value === undefined || typeof value === 'object' || typeof value === 'boolean'
218224
}

0 commit comments

Comments
 (0)