Expose authentication provider registartion/unregistration as single event, fixes #89806

This commit is contained in:
Rachel Macfarlane 2020-01-31 15:52:57 -08:00
parent f11a0b9a29
commit f4786e227c
3 changed files with 27 additions and 14 deletions

View file

@ -25,6 +25,21 @@ declare module 'vscode' {
scopes: string[]
}
/**
* An [event](#Event) which fires when an [AuthenticationProvider](#AuthenticationProvider) is added or removed.
*/
export interface AuthenticationProvidersChangeEvent {
/**
* The ids of the [authenticationProvider](#AuthenticationProvider)s that have been added.
*/
readonly added: string[];
/**
* The ids of the [authenticationProvider](#AuthenticationProvider)s that have been removed..
*/
readonly removed: string[];
}
export interface AuthenticationProvider {
/**
* Used as an identifier for extensions trying to work with a particular
@ -33,6 +48,11 @@ declare module 'vscode' {
*/
readonly id: string;
readonly displayName: string;
/**
* A [enent](#Event) which fires when the array of sessions has changed, or data
* within a session has changed.
*/
readonly onDidChangeSessions: Event<void>;
/**
@ -53,8 +73,7 @@ declare module 'vscode' {
/**
* Fires with the provider id that was registered or unregistered.
*/
export const onDidRegisterAuthenticationProvider: Event<string>;
export const onDidUnregisterAuthenticationProvider: Event<string>;
export const onDidChangeAuthenticationProviders: Event<AuthenticationProvidersChangeEvent>;
export const providers: ReadonlyArray<AuthenticationProvider>;
}

View file

@ -188,11 +188,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
get providers() {
return extHostAuthentication.providers(extension);
},
get onDidRegisterAuthenticationProvider() {
return extHostAuthentication.onDidRegisterAuthenticationProvider;
},
get onDidUnregisterAuthenticationProvider() {
return extHostAuthentication.onDidUnregisterAuthenticationProvider;
get onDidChangeAuthenticationProviders(): Event<vscode.AuthenticationProvidersChangeEvent> {
return extHostAuthentication.onDidChangeAuthenticationProviders;
}
};

View file

@ -55,11 +55,8 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
private _proxy: MainThreadAuthenticationShape;
private _authenticationProviders: Map<string, vscode.AuthenticationProvider> = new Map<string, vscode.AuthenticationProvider>();
private _onDidRegisterAuthenticationProvider = new Emitter<string>();
readonly onDidRegisterAuthenticationProvider: Event<string> = this._onDidRegisterAuthenticationProvider.event;
private _onDidUnregisterAuthenticationProvider = new Emitter<string>();
readonly onDidUnregisterAuthenticationProvider: Event<string> = this._onDidUnregisterAuthenticationProvider.event;
private _onDidChangeAuthenticationProviders = new Emitter<vscode.AuthenticationProvidersChangeEvent>();
readonly onDidChangeAuthenticationProviders: Event<vscode.AuthenticationProvidersChangeEvent> = this._onDidChangeAuthenticationProviders.event;
constructor(mainContext: IMainContext) {
this._proxy = mainContext.getProxy(MainContext.MainThreadAuthentication);
@ -83,13 +80,13 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape {
});
this._proxy.$registerAuthenticationProvider(provider.id, provider.displayName);
this._onDidRegisterAuthenticationProvider.fire(provider.id);
this._onDidChangeAuthenticationProviders.fire({ added: [provider.id], removed: [] });
return new Disposable(() => {
listener.dispose();
this._authenticationProviders.delete(provider.id);
this._proxy.$unregisterAuthenticationProvider(provider.id);
this._onDidUnregisterAuthenticationProvider.fire(provider.id);
this._onDidChangeAuthenticationProviders.fire({ added: [], removed: [provider.id] });
});
}