提交 85bf25fd 编写于 作者: D Daniel Imms

Remove workspace and IWindowService dep on BackupFileService

上级 3903920e
......@@ -458,7 +458,7 @@ export class Workbench implements IPartService {
// Backup File Service
const workspace = this.contextService.getWorkspace();
serviceCollection.set(IBackupFileService, this.instantiationService.createInstance(BackupFileService, workspace ? workspace.resource : null));
serviceCollection.set(IBackupFileService, this.instantiationService.createInstance(BackupFileService, this.windowService.getCurrentWindowId()));
// Backup Service
serviceCollection.set(IBackupModelService, this.instantiationService.createInstance(BackupModelService));
......
......@@ -14,7 +14,6 @@ import { IBackupFileService, BACKUP_FILE_UPDATE_OPTIONS } from 'vs/workbench/ser
import { IBackupService } from 'vs/platform/backup/common/backup';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { TPromise } from 'vs/base/common/winjs.base';
import { readToMatchingString } from 'vs/base/node/stream';
import { IRawTextContent } from 'vs/workbench/services/textfile/common/textfiles';
......@@ -92,13 +91,12 @@ export class BackupFileService implements IBackupFileService {
private ready: TPromise<IBackupFilesModel>;
constructor(
private currentWorkspace: Uri,
windowId: number,
@IEnvironmentService private environmentService: IEnvironmentService,
@IFileService private fileService: IFileService,
@IBackupService private backupService: IBackupService,
@IWindowService private windowService: IWindowService
@IBackupService private backupService: IBackupService
) {
this.ready = this.init();
this.ready = this.init(windowId);
}
private get backupEnabled(): boolean {
......@@ -106,15 +104,15 @@ export class BackupFileService implements IBackupFileService {
return !this.environmentService.isExtensionDevelopment;
}
private init(): TPromise<IBackupFilesModel> {
private init(windowId: number): TPromise<IBackupFilesModel> {
const model = new BackupFilesModel();
if (!this.backupEnabled) {
return TPromise.as(model);
}
console.log('requesting backup workspace for window ' + this.windowService.getCurrentWindowId());
return this.backupService.getBackupPath(this.windowService.getCurrentWindowId()).then(backupPath => {
console.log('requesting backup workspace for window ' + windowId);
return this.backupService.getBackupPath(windowId).then(backupPath => {
console.log('backup workspace from main: ' + backupPath);
this.backupWorkspacePath = backupPath;
return model.resolve(this.backupWorkspacePath);
......
......@@ -17,9 +17,11 @@ import Uri from 'vs/base/common/uri';
import { BackupFileService, BackupFilesModel } from 'vs/workbench/services/backup/node/backupFileService';
import { FileService } from 'vs/workbench/services/files/node/fileService';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IBackupService } from 'vs/platform/backup/common/backup';
import { parseArgs } from 'vs/platform/environment/node/argv';
import { TextModel } from 'vs/editor/common/model/textModel';
import { IRawTextContent } from 'vs/workbench/services/textfile/common/textfiles';
import { TPromise } from 'vs/base/common/winjs.base';
class TestEnvironmentService extends EnvironmentService {
......@@ -32,19 +34,6 @@ class TestEnvironmentService extends EnvironmentService {
get backupWorkspacesPath(): string { return this._backupWorkspacesPath; }
}
class TestBackupFileService extends BackupFileService {
constructor(workspace: Uri, backupHome: string, workspacesJsonPath: string) {
const fileService = new FileService(workspace.fsPath, { disableWatcher: true }, null);
const testEnvironmentService = new TestEnvironmentService(backupHome, workspacesJsonPath);
super(workspace, testEnvironmentService, fileService);
}
public getBackupResource(resource: Uri): Uri {
return super.getBackupResource(resource);
}
}
const parentDir = path.join(os.tmpdir(), 'vsctests', 'service');
const backupHome = path.join(parentDir, 'Backups');
const workspacesJsonPath = path.join(backupHome, 'workspaces.json');
......@@ -58,6 +47,23 @@ const fooBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('
const barBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(barFile.fsPath).digest('hex'));
const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(untitledFile.fsPath.toLowerCase()).digest('hex'));
class TestBackupFileService extends BackupFileService {
constructor(workspace: Uri, backupHome: string, workspacesJsonPath: string) {
const fileService = new FileService(workspace.fsPath, { disableWatcher: true }, null);
const environmentService = new TestEnvironmentService(backupHome, workspacesJsonPath);
const backupService: IBackupService = {
_serviceBrand: null,
getBackupPath: () => TPromise.as(workspaceBackupPath)
};
super(1, environmentService, fileService, backupService);
}
public getBackupResource(resource: Uri): Uri {
return super.getBackupResource(resource);
}
}
suite('BackupFileService', () => {
let service: TestBackupFileService;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册