mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-24 00:05:46 +01:00
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { IServerChannel } from 'vs/base/parts/ipc/node/ipc';
|
|
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces';
|
|
import { URI } from 'vs/base/common/uri';
|
|
import { Event } from 'vs/base/common/event';
|
|
|
|
export class WorkspacesChannel implements IServerChannel {
|
|
|
|
constructor(private service: IWorkspacesMainService) { }
|
|
|
|
listen<T>(_, event: string): Event<T> {
|
|
throw new Error(`Event not found: ${event}`);
|
|
}
|
|
|
|
call(_, command: string, arg?: any): Promise<any> {
|
|
switch (command) {
|
|
case 'createUntitledWorkspace': {
|
|
const rawFolders: IWorkspaceFolderCreationData[] = arg[0];
|
|
const remoteAuthority: string = arg[1];
|
|
let folders: IWorkspaceFolderCreationData[] | undefined = undefined;
|
|
if (Array.isArray(rawFolders)) {
|
|
folders = rawFolders.map(rawFolder => {
|
|
return {
|
|
uri: URI.revive(rawFolder.uri), // convert raw URI back to real URI
|
|
name: rawFolder.name
|
|
} as IWorkspaceFolderCreationData;
|
|
});
|
|
}
|
|
|
|
return this.service.createUntitledWorkspace(folders, remoteAuthority);
|
|
}
|
|
case 'deleteUntitledWorkspace': {
|
|
const w: IWorkspaceIdentifier = arg;
|
|
return this.service.deleteUntitledWorkspace({ id: w.id, configPath: URI.revive(w.configPath) });
|
|
}
|
|
case 'getWorkspaceIdentifier': {
|
|
return this.service.getWorkspaceIdentifier(URI.revive(arg));
|
|
}
|
|
}
|
|
|
|
throw new Error(`Call not found: ${command}`);
|
|
}
|
|
}
|