From 7f37b1ebaa88549f0968bd5a8883305a7e93e5c5 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Wed, 15 Jan 2025 15:39:18 -0800 Subject: [PATCH] Include checking for `github-enterprise` (#237993) * Include checking for `github-enterprise` So that we hide the setup view for GHE.com users after they install Copilot & sign in. Note: this behavior still isn't great if they haven't yet installed Copilot, but to keep this candidate small, we're just focused on fixing the case for when they have Copilot installed already. * Check setting --- .../contrib/chat/browser/chatSetup.ts | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatSetup.ts b/src/vs/workbench/contrib/chat/browser/chatSetup.ts index f8df3fb800007..2e4d60c931c4a 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSetup.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSetup.ts @@ -69,7 +69,7 @@ const defaultChat = { skusDocumentationUrl: product.defaultChatAgent?.skusDocumentationUrl ?? '', publicCodeMatchesUrl: product.defaultChatAgent?.publicCodeMatchesUrl ?? '', upgradePlanUrl: product.defaultChatAgent?.upgradePlanUrl ?? '', - providerId: product.defaultChatAgent?.providerId ?? '', + providerIds: [product.defaultChatAgent?.providerId ?? '', 'github-enterprise'], providerName: product.defaultChatAgent?.providerName ?? '', providerScopes: product.defaultChatAgent?.providerScopes ?? [[]], entitlementUrl: product.defaultChatAgent?.entitlementUrl ?? '', @@ -366,7 +366,8 @@ class ChatSetupRequests extends Disposable { @IRequestService private readonly requestService: IRequestService, @IChatQuotasService private readonly chatQuotasService: IChatQuotasService, @IDialogService private readonly dialogService: IDialogService, - @IOpenerService private readonly openerService: IOpenerService + @IOpenerService private readonly openerService: IOpenerService, + @IConfigurationService private readonly configurationService: IConfigurationService ) { super(); @@ -379,19 +380,19 @@ class ChatSetupRequests extends Disposable { this._register(this.authenticationService.onDidChangeDeclaredProviders(() => this.resolve())); this._register(this.authenticationService.onDidChangeSessions(e => { - if (e.providerId === defaultChat.providerId) { + if (defaultChat.providerIds.includes(e.providerId)) { this.resolve(); } })); this._register(this.authenticationService.onDidRegisterAuthenticationProvider(e => { - if (e.id === defaultChat.providerId) { + if (defaultChat.providerIds.includes(e.id)) { this.resolve(); } })); this._register(this.authenticationService.onDidUnregisterAuthenticationProvider(e => { - if (e.id === defaultChat.providerId) { + if (defaultChat.providerIds.includes(e.id)) { this.resolve(); } })); @@ -438,9 +439,20 @@ class ChatSetupRequests extends Disposable { } private async findMatchingProviderSession(token: CancellationToken): Promise { - const sessions = await this.authenticationService.getSessions(defaultChat.providerId); - if (token.isCancellationRequested) { - return undefined; + let sessions: ReadonlyArray = []; + const authProviderConfigValue = this.configurationService.getValue('github.copilot.advanced.authProvider'); + if (authProviderConfigValue) { + sessions = await this.authenticationService.getSessions(authProviderConfigValue); + } else { + for (const providerId of defaultChat.providerIds) { + if (token.isCancellationRequested) { + return undefined; + } + sessions = await this.authenticationService.getSessions(providerId); + if (sessions.length) { + break; + } + } } for (const session of sessions) { @@ -787,7 +799,7 @@ class ChatSetupController extends Disposable { } if (!session) { - session = (await this.authenticationService.getSessions(defaultChat.providerId)).at(0); + session = (await this.authenticationService.getSessions(defaultChat.providerIds[0])).at(0); if (!session) { return; // unexpected } @@ -817,7 +829,7 @@ class ChatSetupController extends Disposable { try { showCopilotView(this.viewsService, this.layoutService); - session = await this.authenticationService.createSession(defaultChat.providerId, defaultChat.providerScopes[0]); + session = await this.authenticationService.createSession(defaultChat.providerIds[0], defaultChat.providerScopes[0]); entitlement = await this.requests.forceResolveEntitlement(session); } catch (error) { // noop