diff --git a/src/vs/workbench/api/node/apiCommands.ts b/src/vs/workbench/api/node/apiCommands.ts index 0f048e7fa4d..392a0238c8c 100644 --- a/src/vs/workbench/api/node/apiCommands.ts +++ b/src/vs/workbench/api/node/apiCommands.ts @@ -13,6 +13,8 @@ import { EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGro import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IWindowsService, IOpenSettings } from 'vs/platform/windows/common/windows'; import { IDownloadService } from 'vs/platform/download/common/download'; +import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces'; +import { IRecent } from 'vs/platform/history/common/history'; // ----------------------------------------------------------------- // The following commands are registered on both sides separately. @@ -141,6 +143,29 @@ export class RemoveFromRecentlyOpenedAPICommand { } CommandsRegistry.registerCommand(RemoveFromRecentlyOpenedAPICommand.ID, adjustHandler(RemoveFromRecentlyOpenedAPICommand.execute)); +interface RecentEntry { + uri: URI; + type: 'workspace' | 'folder' | 'file'; + label?: string; +} + +CommandsRegistry.registerCommand('_workbench.addToRecentlyOpened', async function (accessor: ServicesAccessor, recentEntry: RecentEntry) { + const windowsService = accessor.get(IWindowsService); + const workspacesService = accessor.get(IWorkspacesService); + let recent: IRecent | undefined = undefined; + const uri = recentEntry.uri; + const label = recentEntry.label; + if (recentEntry.type === 'workspace') { + const workspace = await workspacesService.getWorkspaceIdentifier(uri); + recent = { workspace, label }; + } else if (recentEntry.type === 'folder') { + recent = { folderUri: uri, label }; + } else { + recent = { fileUri: uri, label }; + } + return windowsService.addRecentlyOpened([recent]); +}); + export class SetEditorLayoutAPICommand { public static ID = 'vscode.setEditorLayout'; public static execute(executor: ICommandsExecutor, layout: EditorGroupLayout): Promise {