Skip to content

Commit

Permalink
feat: add support for custom fs provider
Browse files Browse the repository at this point in the history
We're looking to add our own providers for `user` and `cache` fs so they
can be persisted between sessions. With this change, we don't break the
existing API but we can allow for adding custom filesystems for these
providers.
  • Loading branch information
CompuIves committed Nov 7, 2023
1 parent 29f389a commit fe49473
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions src/service-override/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -504,6 +525,7 @@ export function registerFileSystemOverlay (priority: number, provider: IFileSyst
}

export {
CustomFileSystemProviders,
IFileSystemProviderWithFileReadWriteCapability,
FileSystemProviderCapabilities,
FileType,
Expand Down

0 comments on commit fe49473

Please sign in to comment.