diff --git a/src/vs/workbench/browser/workbench.ts b/src/vs/workbench/browser/workbench.ts index 27fa22c8ae375a3f54b5528b2419fd1d5a333a21..fe9a0457c1176f61a0622b3c228b794629c967be 100644 --- a/src/vs/workbench/browser/workbench.ts +++ b/src/vs/workbench/browser/workbench.ts @@ -192,8 +192,8 @@ export class Workbench extends Layout { // TODO@Ben legacy file service const fileService = accessor.get(IFileService) as any; - if (typeof fileService.setImpl === 'function') { - fileService.setImpl(accessor.get(ILegacyFileService)); + if (typeof fileService.setLegacyService === 'function') { + fileService.setLegacyService(accessor.get(ILegacyFileService)); } // TODO@Sandeep debt around cyclic dependencies diff --git a/src/vs/workbench/services/files/node/fileService.ts b/src/vs/workbench/services/files/node/fileService.ts index f870dade4745391afe59d569b6911fa397da2fef..963e7718a67051deb52969fa859b40e4cde99dad 100644 --- a/src/vs/workbench/services/files/node/fileService.ts +++ b/src/vs/workbench/services/files/node/fileService.ts @@ -207,7 +207,7 @@ export class FileService extends Disposable implements ILegacyFileService, IFile } registerProvider(scheme: string, provider: IFileSystemProvider): IDisposable { - throw new Error('not implemented'); + return Disposable.None; } activateProvider(scheme: string): Promise { diff --git a/src/vs/workbench/services/files2/common/fileService2.ts b/src/vs/workbench/services/files2/common/fileService2.ts index af6a4d5875a711ae2d168a78fce461b0456c730b..d19c9799e3b4f806d6e0e159b5053adcc25f6af6 100644 --- a/src/vs/workbench/services/files2/common/fileService2.ts +++ b/src/vs/workbench/services/files2/common/fileService2.ts @@ -19,25 +19,34 @@ export class FileService2 extends Disposable implements IFileService { //#region TODO@Ben HACKS - private _impl: IFileService; + private _legacy: IFileService | null; - setImpl(service: IFileService): void { - this._impl = this._register(service); + setLegacyService(legacy: IFileService): void { + this._legacy = this._register(legacy); - this._register(service.onFileChanges(e => this._onFileChanges.fire(e))); - this._register(service.onAfterOperation(e => this._onAfterOperation.fire(e))); + this._register(legacy.onFileChanges(e => this._onFileChanges.fire(e))); + this._register(legacy.onAfterOperation(e => this._onAfterOperation.fire(e))); this.provider.forEach((provider, scheme) => { - this._impl.registerProvider(scheme, provider); + legacy.registerProvider(scheme, provider); }); + + this.joinOnImplResolve(legacy); } //#endregion _serviceBrand: ServiceIdentifier; + private joinOnLegacy: Promise; + private joinOnImplResolve: (service: IFileService) => void; + constructor(@ILogService private logService: ILogService) { super(); + + this.joinOnLegacy = new Promise(resolve => { + this.joinOnImplResolve = resolve; + }); } //#region File System Provider @@ -56,8 +65,8 @@ export class FileService2 extends Disposable implements IFileService { } let legacyDisposal: IDisposable; - if (this._impl) { - legacyDisposal = this._impl.registerProvider(scheme, provider); + if (this._legacy) { + legacyDisposal = this._legacy.registerProvider(scheme, provider); } else { legacyDisposal = Disposable.None; } @@ -285,22 +294,28 @@ export class FileService2 extends Disposable implements IFileService { //#region File Reading/Writing - get encoding(): IResourceEncodings { return this._impl.encoding; } + get encoding(): IResourceEncodings { + if (!this._legacy) { + throw new Error('Legacy file service not ready yet'); + } + + return this._legacy.encoding; + } createFile(resource: URI, content?: string, options?: ICreateFileOptions): Promise { - return this._impl.createFile(resource, content, options); + return this.joinOnLegacy.then(legacy => legacy.createFile(resource, content, options)); } resolveContent(resource: URI, options?: IResolveContentOptions): Promise { - return this._impl.resolveContent(resource, options); + return this.joinOnLegacy.then(legacy => legacy.resolveContent(resource, options)); } resolveStreamContent(resource: URI, options?: IResolveContentOptions): Promise { - return this._impl.resolveStreamContent(resource, options); + return this.joinOnLegacy.then(legacy => legacy.resolveStreamContent(resource, options)); } updateContent(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): Promise { - return this._impl.updateContent(resource, value, options); + return this.joinOnLegacy.then(legacy => legacy.updateContent(resource, value, options)); } //#endregion @@ -346,11 +361,11 @@ export class FileService2 extends Disposable implements IFileService { return this.doMoveCopyWithSameProvider(source, target, true /* keep copy */, overwrite); } - return this._impl.copyFile(source, target, overwrite); // TODO@ben implement properly + return this.joinOnLegacy.then(legacy => legacy.copyFile(source, target, overwrite)); } private async doCopyWithDifferentProvider(source: URI, target: URI, overwrite?: boolean): Promise { - return this._impl.copyFile(source, target, overwrite); // TODO@ben implement properly + return this.joinOnLegacy.then(legacy => legacy.copyFile(source, target, overwrite)); } private async doMoveCopyWithSameProvider(source: URI, target: URI, keepCopy: boolean, overwrite?: boolean): Promise { @@ -444,7 +459,8 @@ export class FileService2 extends Disposable implements IFileService { async del(resource: URI, options?: { useTrash?: boolean; recursive?: boolean; }): Promise { if (options && options.useTrash) { - return this._impl.del(resource, options); //TODO@ben this is https://github.com/Microsoft/vscode/issues/48259 + //TODO@ben this is https://github.com/Microsoft/vscode/issues/48259 + return this.joinOnLegacy.then(legacy => legacy.del(resource, options)); } const provider = this.throwIfFileSystemIsReadonly(await this.withProvider(resource)); @@ -464,11 +480,11 @@ export class FileService2 extends Disposable implements IFileService { get onFileChanges(): Event { return this._onFileChanges.event; } watchFileChanges(resource: URI): void { - this._impl.watchFileChanges(resource); + this.joinOnLegacy.then(legacy => legacy.watchFileChanges(resource)); } unwatchFileChanges(resource: URI): void { - this._impl.unwatchFileChanges(resource); + this.joinOnLegacy.then(legacy => legacy.unwatchFileChanges(resource)); } //#endregion diff --git a/src/vs/workbench/services/files2/test/node/diskFileService.test.ts b/src/vs/workbench/services/files2/test/node/diskFileService.test.ts index e17bc6c1c9cc61d30f1083c0455eb8cb474fffcb..aa0715b491a5d96f32cf4d7cdeb42e4435be8fe1 100644 --- a/src/vs/workbench/services/files2/test/node/diskFileService.test.ts +++ b/src/vs/workbench/services/files2/test/node/diskFileService.test.ts @@ -55,7 +55,7 @@ suite('Disk File Service', () => { await copy(sourceDir, testDir); const legacyService = new FileService(new TestContextService(new Workspace(testDir, toWorkspaceFolders([{ path: testDir }]))), TestEnvironmentService, new TestTextResourceConfigurationService(), new TestConfigurationService(), new TestLifecycleService(), new TestStorageService(), new TestNotificationService(), { disableWatcher: true }); - service.setImpl(legacyService); + service.setLegacyService(legacyService); }); teardown(async () => {