files2 - always trigger activation event for fs provider, even if already registered

This commit is contained in:
Benjamin Pasero 2019-03-19 09:09:30 +01:00
parent c0432ebae5
commit 466e69b8ed
2 changed files with 16 additions and 5 deletions

View file

@ -69,12 +69,10 @@ export class FileService2 extends Disposable implements IFileService {
}
activateProvider(scheme: string): Promise<void> {
if (this.provider.has(scheme)) {
return Promise.resolve(); // provider is already here! TODO@ben should we still activate by event but not wait for it?
}
// Emit an event that we are about to activate a provider with the given scheme.
// Listeners can participate in the activation by registering a provider for it.
const joiners: Promise<void>[] = [];
this._onWillActivateFileSystemProvider.fire({
scheme,
join(promise) {
@ -84,6 +82,12 @@ export class FileService2 extends Disposable implements IFileService {
},
});
if (this.provider.has(scheme)) {
return Promise.resolve(); // provider is already here so we can return directly
}
// If the provider is not yet there, make sure to join on the listeners assuming
// that it takes a bit longer to register the file system provider.
return Promise.all(joiners).then(() => undefined);
}

View file

@ -23,8 +23,11 @@ suite('File Service 2', () => {
});
let registrationDisposable: IDisposable;
let callCount = 0;
service.onWillActivateFileSystemProvider(e => {
if (e.scheme === 'test') {
callCount++;
if (e.scheme === 'test' && callCount === 1) {
e.join(new Promise(resolve => {
registrationDisposable = service.registerProvider('test', new NullFileSystemProvider());
@ -40,6 +43,10 @@ suite('File Service 2', () => {
assert.equal(registrations.length, 1);
assert.equal(registrations[0].scheme, 'test');
assert.equal(registrations[0].added, true);
assert.ok(registrationDisposable);
await service.activateProvider('test');
assert.equal(callCount, 2); // activation is called again
registrationDisposable.dispose();