diff --git a/src/service-override/files.ts b/src/service-override/files.ts index eb89bdd3..bbffc3c3 100644 --- a/src/service-override/files.ts +++ b/src/service-override/files.ts @@ -457,30 +457,51 @@ class DelegateFileSystemProvider implements IFileSystemProvider { const fileSystemProvider = new OverlayFileSystemProvider() fileSystemProvider.register(0, new MkdirpOnWriteInMemoryFileSystemProvider()) +interface CustomFileSystemProviders { + [scheme: string]: IFileSystemProvider +} + const extensionFileSystemProvider = new RegisteredFileSystemProvider(true) class MemoryFileService extends FileService { - constructor (@ILogService logService: ILogService) { + constructor (@ILogService logService: ILogService, additionalProviders: CustomFileSystemProviders = {}) { super(logService) - const userMemoryFileSystem = new InMemoryFileSystemProvider() - - this.registerProvider('user', userMemoryFileSystem) - this.registerProvider('extension', extensionFileSystemProvider) - this.registerProvider('cache', new InMemoryFileSystemProvider()) - this.registerProvider('logs', new InMemoryFileSystemProvider()) - this.registerProvider(Schemas.vscodeUserData, new InMemoryFileSystemProvider()) - this.registerProvider(Schemas.tmp, new InMemoryFileSystemProvider()) - let fileSystemProviderDisposable = this.registerProvider('file', fileSystemProvider) - fileSystemProvider.onDidChangeOverlays(() => { - fileSystemProviderDisposable.dispose() - fileSystemProviderDisposable = this.registerProvider('file', fileSystemProvider) - }) + if (additionalProviders.user == null) { + const userMemoryFileSystem = new InMemoryFileSystemProvider() + this.registerProvider('user', userMemoryFileSystem) + } + if (additionalProviders.extension == null) { + this.registerProvider('extension', extensionFileSystemProvider) + } + if (additionalProviders.cache == null) { + this.registerProvider('cache', new InMemoryFileSystemProvider()) + } + if (additionalProviders.logs == null) { + this.registerProvider('logs', new InMemoryFileSystemProvider()) + } + if (additionalProviders[Schemas.vscodeUserData] == null) { + this.registerProvider(Schemas.vscodeUserData, new InMemoryFileSystemProvider()) + } + if (additionalProviders[Schemas.tmp] == null) { + this.registerProvider(Schemas.tmp, new InMemoryFileSystemProvider()) + } + if (additionalProviders.file == null) { + let fileSystemProviderDisposable = this.registerProvider('file', fileSystemProvider) + fileSystemProvider.onDidChangeOverlays(() => { + fileSystemProviderDisposable.dispose() + fileSystemProviderDisposable = this.registerProvider('file', fileSystemProvider) + }) + } + + for (const [scheme, provider] of Object.entries(additionalProviders)) { + this.registerProvider(scheme, provider) + } } } -export default function getServiceOverride (): IEditorOverrideServices { +export default function getServiceOverride (customProviders?: CustomFileSystemProviders): IEditorOverrideServices { return { - [IFileService.toString()]: new SyncDescriptor(MemoryFileService, [], true) + [IFileService.toString()]: new SyncDescriptor(MemoryFileService, [customProviders], true) } } @@ -504,6 +525,7 @@ export function registerFileSystemOverlay (priority: number, provider: IFileSyst } export { + CustomFileSystemProviders, IFileSystemProviderWithFileReadWriteCapability, FileSystemProviderCapabilities, FileType,