提交 48854cd4 编写于 作者: B Benjamin Pasero

IWorkspace => IWorkspaceIdentifier

上级 7a35ef4b
......@@ -24,7 +24,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { KeyboardLayoutMonitor } from 'vs/code/electron-main/keyboard';
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { ICodeWindow } from "vs/platform/windows/electron-main/windows";
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export interface IWindowState {
width?: number;
......@@ -265,7 +265,7 @@ export class CodeWindow implements ICodeWindow {
return this.currentConfig ? this.currentConfig.backupPath : void 0;
}
public get openedWorkspace(): IWorkspace {
public get openedWorkspace(): IWorkspaceIdentifier {
return this.currentConfig ? this.currentConfig.workspace : void 0;
}
......
......@@ -29,7 +29,7 @@ import { IWindowsMainService, IOpenConfiguration } from "vs/platform/windows/ele
import { IHistoryMainService } from "vs/platform/history/electron-main/historyMainService";
import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { TPromise } from "vs/base/common/winjs.base";
import { IWorkspacesMainService, IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspacesMainService, IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
enum WindowError {
UNRESPONSIVE,
......@@ -45,7 +45,7 @@ interface ILegacyWindowState extends IWindowState {
}
interface IWindowState {
workspace?: IWorkspace;
workspace?: IWorkspaceIdentifier;
folderPath?: string;
backupPath: string;
uiState: ISingleWindowState;
......@@ -67,7 +67,7 @@ interface IOpenBrowserWindowOptions {
userEnv?: IProcessEnvironment;
cli?: ParsedArgs;
workspace?: IWorkspace;
workspace?: IWorkspaceIdentifier;
folderPath?: string;
initialStartup?: boolean;
......@@ -85,7 +85,7 @@ interface IOpenBrowserWindowOptions {
interface IWindowToOpen extends IPath {
// the workspace for a Code instance to open
workspace?: IWorkspace;
workspace?: IWorkspaceIdentifier;
// the folder path for a Code instance to open
folderPath?: string;
......@@ -373,8 +373,8 @@ export class WindowsManager implements IWindowsMainService {
private doOpen(
openConfig: IOpenConfiguration,
workspacesToOpen: IWorkspace[],
workspacesToRestore: IWorkspace[],
workspacesToOpen: IWorkspaceIdentifier[],
workspacesToRestore: IWorkspaceIdentifier[],
foldersToOpen: string[],
foldersToRestore: string[],
emptyToRestore: string[],
......
......@@ -10,10 +10,10 @@ import * as fs from 'fs';
import * as platform from 'vs/base/common/platform';
import * as paths from 'vs/base/common/paths';
import { OpenContext } from 'vs/platform/windows/common/windows';
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export interface ISimpleWindow {
openedWorkspace?: IWorkspace;
openedWorkspace?: IWorkspaceIdentifier;
openedFolderPath?: string;
openedFilePath?: string;
extensionDevelopmentPath?: string;
......@@ -127,7 +127,7 @@ export function findWindowOnFolder<W extends ISimpleWindow>(windows: W[], folder
return null;
}
export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], workspace: IWorkspace): W {
export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], workspace: IWorkspaceIdentifier): W {
if (windows.length) {
const res = windows.filter(w => {
......
......@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export interface IBackupWorkspacesFormat {
rootWorkspaces: IWorkspace[];
rootWorkspaces: IWorkspaceIdentifier[];
folderWorkspaces: string[];
emptyWorkspaces: string[];
}
......@@ -17,11 +17,11 @@ export const IBackupMainService = createDecorator<IBackupMainService>('backupMai
export interface IBackupMainService {
_serviceBrand: any;
getWorkspaceBackups(): IWorkspace[];
getWorkspaceBackups(): IWorkspaceIdentifier[];
getFolderBackupPaths(): string[];
getEmptyWindowBackupPaths(): string[];
registerWorkspaceBackupSync(workspace: IWorkspace): string;
registerWorkspaceBackupSync(workspace: IWorkspaceIdentifier): string;
registerFolderBackupSync(folderPath: string): string;
registerEmptyWindowBackupSync(backupFolder?: string): string;
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IFilesConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files';
import { ILogService } from "vs/platform/log/common/log";
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export class BackupMainService implements IBackupMainService {
......@@ -36,7 +36,7 @@ export class BackupMainService implements IBackupMainService {
this.loadSync();
}
public getWorkspaceBackups(): IWorkspace[] {
public getWorkspaceBackups(): IWorkspaceIdentifier[] {
if (this.isHotExitOnExitAndWindowClose()) {
// Only non-folder windows are restored on main process launch when
// hot exit is configured as onExitAndWindowClose.
......@@ -64,7 +64,7 @@ export class BackupMainService implements IBackupMainService {
return this.backups.emptyWorkspaces.slice(0); // return a copy
}
public registerWorkspaceBackupSync(workspace: IWorkspace): string {
public registerWorkspaceBackupSync(workspace: IWorkspaceIdentifier): string {
this.pushBackupPathsSync(workspace, this.backups.rootWorkspaces);
return path.join(this.backupHome, workspace.id);
......@@ -88,14 +88,14 @@ export class BackupMainService implements IBackupMainService {
return path.join(this.backupHome, backupFolder);
}
private pushBackupPathsSync(workspaceIdentifier: string | IWorkspace, target: (string | IWorkspace)[]): void {
private pushBackupPathsSync(workspaceIdentifier: string | IWorkspaceIdentifier, target: (string | IWorkspaceIdentifier)[]): void {
if (this.indexOf(workspaceIdentifier, target) === -1) {
target.push(workspaceIdentifier);
this.saveSync();
}
}
protected removeBackupPathSync(workspaceIdentifier: string | IWorkspace, target: (string | IWorkspace)[]): void {
protected removeBackupPathSync(workspaceIdentifier: string | IWorkspaceIdentifier, target: (string | IWorkspaceIdentifier)[]): void {
if (!target) {
return;
}
......@@ -107,7 +107,7 @@ export class BackupMainService implements IBackupMainService {
this.saveSync();
}
private indexOf(workspaceIdentifier: string | IWorkspace, target: (string | IWorkspace)[]): number {
private indexOf(workspaceIdentifier: string | IWorkspaceIdentifier, target: (string | IWorkspaceIdentifier)[]): number {
if (!target) {
return -1;
}
......@@ -117,7 +117,7 @@ export class BackupMainService implements IBackupMainService {
return arrays.firstIndex(target, id => this.sanitizeId(id) === sanitizedWorkspaceIdentifier);
}
private sanitizeId(workspaceIdentifier: string | IWorkspace): string {
private sanitizeId(workspaceIdentifier: string | IWorkspaceIdentifier): string {
if (typeof workspaceIdentifier === 'string') {
return this.sanitizePath(workspaceIdentifier);
}
......@@ -180,9 +180,9 @@ export class BackupMainService implements IBackupMainService {
}
private validateBackupWorkspaces(backups: IBackupWorkspacesFormat): void {
const staleBackupWorkspaces: { workspaceIdentifier: string | IWorkspace; backupPath: string; target: (string | IWorkspace)[] }[] = [];
const staleBackupWorkspaces: { workspaceIdentifier: string | IWorkspaceIdentifier; backupPath: string; target: (string | IWorkspaceIdentifier)[] }[] = [];
const workspaceAndFolders: { workspaceIdentifier: string | IWorkspace, target: (string | IWorkspace)[] }[] = [];
const workspaceAndFolders: { workspaceIdentifier: string | IWorkspaceIdentifier, target: (string | IWorkspaceIdentifier)[] }[] = [];
workspaceAndFolders.push(...backups.rootWorkspaces.map(r => ({ workspaceIdentifier: r, target: backups.rootWorkspaces })));
workspaceAndFolders.push(...backups.folderWorkspaces.map(f => ({ workspaceIdentifier: f, target: backups.folderWorkspaces })));
......
......@@ -20,7 +20,7 @@ import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup';
import { HotExitConfiguration } from 'vs/platform/files/common/files';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { LogMainService } from "vs/platform/log/common/log";
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
import { createHash } from "crypto";
class TestBackupMainService extends BackupMainService {
......@@ -39,7 +39,7 @@ class TestBackupMainService extends BackupMainService {
return this.backups;
}
public removeBackupPathSync(workspaceIdentifier: string | IWorkspace, target: (string | IWorkspace)[]): void {
public removeBackupPathSync(workspaceIdentifier: string | IWorkspaceIdentifier, target: (string | IWorkspaceIdentifier)[]): void {
return super.removeBackupPathSync(workspaceIdentifier, target);
}
......@@ -60,11 +60,10 @@ class TestBackupMainService extends BackupMainService {
}
}
function toWorkspace(path: string): IWorkspace {
function toWorkspace(path: string): IWorkspaceIdentifier {
return {
id: createHash('md5').update(sanitizePath(path)).digest('hex'),
configPath: path,
folders: []
configPath: path
};
}
......
......@@ -11,7 +11,7 @@ import Event from 'vs/base/common/event';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IProcessEnvironment } from 'vs/base/common/platform';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export const IWindowsService = createDecorator<IWindowsService>('windowsService');
......@@ -47,7 +47,7 @@ export interface IWindowsService {
quit(): TPromise<void>;
relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void>;
openWorkspace(windowId: number, workspace: IWorkspace): TPromise<void>;
openWorkspace(windowId: number, workspace: IWorkspaceIdentifier): TPromise<void>;
// Shared process
whenSharedProcessReady(): TPromise<void>;
......@@ -207,7 +207,7 @@ export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
perfAppReady?: number;
perfWindowLoadTime?: number;
workspace?: IWorkspace;
workspace?: IWorkspaceIdentifier;
folderPath?: string;
backupPath?: string;
......
......@@ -10,7 +10,7 @@ import Event, { buffer } from 'vs/base/common/event';
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
import { IWindowsService } from './windows';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export interface IWindowsChannel extends IChannel {
call(command: 'event:onWindowOpen'): TPromise<number>;
......@@ -43,7 +43,7 @@ export interface IWindowsChannel extends IChannel {
call(command: 'getWindows'): TPromise<{ id: number; path: string; title: string; }[]>;
call(command: 'getWindowCount'): TPromise<number>;
call(command: 'relaunch', arg: { addArgs?: string[], removeArgs?: string[] }): TPromise<number>;
call(command: 'openWorkspace', arg: [number, IWorkspace]): TPromise<void>;
call(command: 'openWorkspace', arg: [number, IWorkspaceIdentifier]): TPromise<void>;
call(command: 'whenSharedProcessReady'): TPromise<void>;
call(command: 'toggleSharedProcess'): TPromise<void>;
call(command: 'log', arg: [string, string[]]): TPromise<void>;
......@@ -218,7 +218,7 @@ export class WindowsChannelClient implements IWindowsService {
return this.channel.call('relaunch', [options]);
}
openWorkspace(windowId: number, workspace: IWorkspace): TPromise<void> {
openWorkspace(windowId: number, workspace: IWorkspaceIdentifier): TPromise<void> {
return this.channel.call('openWorkspace', [windowId, workspace]);
}
......
......@@ -12,7 +12,7 @@ import Event from 'vs/base/common/event';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IProcessEnvironment } from 'vs/base/common/platform';
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export interface ICodeWindow {
id: number;
......@@ -20,7 +20,7 @@ export interface ICodeWindow {
config: IWindowConfiguration;
openedFolderPath: string;
openedWorkspace: IWorkspace;
openedWorkspace: IWorkspaceIdentifier;
lastFocusTime: number;
......
......@@ -20,7 +20,7 @@ import { ILifecycleService } from "vs/platform/lifecycle/electron-main/lifecycle
import { IWindowsMainService, ISharedProcess } from "vs/platform/windows/electron-main/windows";
import { IHistoryMainService } from "vs/platform/history/electron-main/historyMainService";
import { findExtensionDevelopmentWindow } from "vs/code/node/windowsFinder";
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export class WindowsService implements IWindowsService, IDisposable {
......@@ -323,7 +323,7 @@ export class WindowsService implements IWindowsService, IDisposable {
return TPromise.as(null);
}
openWorkspace(windowId: number, workspace: IWorkspace): TPromise<void> {
openWorkspace(windowId: number, workspace: IWorkspaceIdentifier): TPromise<void> {
const codeWindow = this.windowsMainService.getWindowById(windowId);
if (codeWindow) {
......
......@@ -11,7 +11,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
export const IWorkspacesMainService = createDecorator<IWorkspacesMainService>('workspacesMainService');
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');
export interface IWorkspace extends IStoredWorkspace {
export interface IWorkspaceIdentifier {
id: string;
configPath: string;
}
......@@ -23,11 +24,11 @@ export interface IStoredWorkspace {
export interface IWorkspacesMainService extends IWorkspacesService {
_serviceBrand: any;
resolveWorkspaceSync(path: string): IWorkspace;
resolveWorkspaceSync(path: string): IWorkspaceIdentifier;
}
export interface IWorkspacesService {
_serviceBrand: any;
createWorkspace(folders?: string[]): TPromise<IWorkspace>;
createWorkspace(folders?: string[]): TPromise<IWorkspaceIdentifier>;
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IWorkspacesService, IWorkspace } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspacesService, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
export interface IWorkspacesChannel extends IChannel {
call(command: 'createWorkspace', arg: [string[]]): TPromise<string>;
......@@ -33,7 +33,7 @@ export class WorkspacesChannelClient implements IWorkspacesService {
constructor(private channel: IWorkspacesChannel) { }
createWorkspace(folders?: string[]): TPromise<IWorkspace> {
createWorkspace(folders?: string[]): TPromise<IWorkspaceIdentifier> {
return this.channel.call('createWorkspace', folders);
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
'use strict';
import { IWorkspacesMainService, IWorkspace, IStoredWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspacesMainService, IWorkspaceIdentifier, IStoredWorkspace } from "vs/platform/workspaces/common/workspaces";
import { TPromise } from "vs/base/common/winjs.base";
import { isParent } from "vs/platform/files/common/files";
import { IEnvironmentService } from "vs/platform/environment/common/environment";
......@@ -24,7 +24,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
this.workspacesHome = environmentService.workspacesHome;
}
public resolveWorkspaceSync(path: string): IWorkspace {
public resolveWorkspaceSync(path: string): IWorkspaceIdentifier {
const isWorkspace = isParent(path, this.environmentService.workspacesHome, !isLinux /* ignore case */) || extname(path) === '.code';
if (!isWorkspace) {
return null; // does not look like a valid workspace config file
......@@ -38,7 +38,6 @@ export class WorkspacesMainService implements IWorkspacesMainService {
return {
id: workspace.id,
folders: workspace.folders,
configPath: path
};
} catch (error) {
......@@ -46,7 +45,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
}
}
public createWorkspace(folders: string[] = []): TPromise<IWorkspace> {
public createWorkspace(folders: string[] = []): TPromise<IWorkspaceIdentifier> {
const workspaceId = this.nextWorkspaceId();
const workspaceConfigFolder = join(this.workspacesHome, workspaceId);
const workspaceConfigPath = join(workspaceConfigFolder, 'workspace.json');
......
......@@ -49,11 +49,10 @@ suite('WorkspacesMainService', () => {
return service.createWorkspace().then(workspace => {
assert.ok(workspace);
assert.ok(fs.existsSync(workspace.configPath));
assert.equal(workspace.folders.length, 0);
const ws = JSON.parse(fs.readFileSync(workspace.configPath).toString()) as IStoredWorkspace;
assert.equal(ws.id, workspace.id);
assert.deepEqual(ws.folders, workspace.folders);
assert.deepEqual(ws.folders.length, 0);
done();
});
......@@ -63,13 +62,12 @@ suite('WorkspacesMainService', () => {
return service.createWorkspace([process.cwd(), os.tmpdir()]).then(workspace => {
assert.ok(workspace);
assert.ok(fs.existsSync(workspace.configPath));
assert.equal(workspace.folders.length, 2);
assert.equal(workspace.folders[0], process.cwd());
assert.equal(workspace.folders[1], os.tmpdir());
const ws = JSON.parse(fs.readFileSync(workspace.configPath).toString()) as IStoredWorkspace;
assert.equal(ws.id, workspace.id);
assert.deepEqual(ws.folders, workspace.folders);
assert.equal(ws.folders.length, 2);
assert.equal(ws.folders[0], process.cwd());
assert.equal(ws.folders[1], os.tmpdir());
done();
});
......@@ -87,7 +85,7 @@ suite('WorkspacesMainService', () => {
workspace.configPath = newPath;
const resolved = service.resolveWorkspaceSync(workspace.configPath);
assert.deepEqual(resolved, workspace);
assert.deepEqual(resolved, { id: workspace.id, configPath: workspace.configPath });
done();
});
......
......@@ -54,7 +54,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { isLinux } from 'vs/base/common/platform';
import { generateUuid } from 'vs/base/common/uuid';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { IWorkspace } from "vs/platform/workspaces/common/workspaces";
import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces";
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, void 0);
......@@ -1062,7 +1062,7 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}
openWorkspace(windowId: number, workspace: IWorkspace): TPromise<void> {
openWorkspace(windowId: number, workspace: IWorkspaceIdentifier): TPromise<void> {
return TPromise.as(void 0);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册