Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chat - tweaks to chat setup #233178

Merged
merged 14 commits into from
Nov 6, 2024
Prev Previous commit
.
  • Loading branch information
bpasero committed Nov 6, 2024
commit 3e9c93486d4e44d3e97f2220a48bd3ba712fb3c7
32 changes: 24 additions & 8 deletions src/vs/workbench/contrib/chat/common/chatSetup.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class ChatSetupContribution extends Disposable implements IWorkbenchContribution
}

this.checkExtensionInstallation(entitlement);
this.registerListeners(entitlement);

this.registerEntitlementListeners(entitlement);
this.registerAuthListeners(entitlement);
}

private async checkExtensionInstallation(entitlement: IGitHubEntitlement): Promise<void> {
Expand All @@ -68,7 +70,7 @@ class ChatSetupContribution extends Disposable implements IWorkbenchContribution
this.updateExtensionInstalled(installed ? true : false);
}

private registerListeners(entitlement: IGitHubEntitlement): void {
private registerEntitlementListeners(entitlement: IGitHubEntitlement): void {
this._register(this.extensionService.onDidChangeExtensions(result => {
for (const extension of result.removed) {
if (ExtensionIdentifier.equals(entitlement.extensionId, extension.identifier)) {
Expand All @@ -88,25 +90,39 @@ class ChatSetupContribution extends Disposable implements IWorkbenchContribution
this._register(this.authenticationService.onDidChangeSessions(e => {
if (e.providerId === entitlement.providerId) {
if (e.event.added?.length) {
this.chatSetupSignedInContextKey.set(true);
this.resolveEntitlement(entitlement, e.event.added[0]);
} else if (e.event.removed?.length) {
this.chatSetupSignedInContextKey.set(false);
this.chatSetupEntitledContextKey.set(false);
}
}
}));

this._register(this.authenticationService.onDidRegisterAuthenticationProvider(async e => {
if (e.id === entitlement.providerId) {
this.chatSetupSignedInContextKey.set(true);
this.resolveEntitlement(entitlement, (await this.authenticationService.getSessions(e.id))[0]);
}
}));
}

this._register(this.authenticationService.onDidUnregisterAuthenticationProvider(async e => {
if (e.id === entitlement.providerId) {
this.chatSetupSignedInContextKey.set(false);
private registerAuthListeners(entitlement: IGitHubEntitlement): void {
const hasProviderSessions = async () => {
const sessions = await this.authenticationService.getSessions(entitlement.providerId);
return sessions.length > 0;
};

const handleDeclaredAuthProviders = async () => {
if (this.authenticationService.declaredProviders.find(p => p.id === entitlement.providerId)) {
this.chatSetupSignedInContextKey.set(await hasProviderSessions());
}
};
this._register(this.authenticationService.onDidChangeDeclaredProviders(handleDeclaredAuthProviders));
this._register(this.authenticationService.onDidRegisterAuthenticationProvider(handleDeclaredAuthProviders));

handleDeclaredAuthProviders();

this._register(this.authenticationService.onDidChangeSessions(async ({ providerId }) => {
if (providerId === entitlement.providerId) {
this.chatSetupSignedInContextKey.set(await hasProviderSessions());
}
}));
}
Expand Down
Loading