Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/remoteCodeSearch/node/codeSearchRepoAuth.ts
13400 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as l10n from '@vscode/l10n';
7
import { createDecorator as createServiceIdentifier } from '../../../util/vs/platform/instantiation/common/instantiation';
8
import { IAuthenticationService } from '../../authentication/common/authentication';
9
import { ResolvedRepoRemoteInfo } from '../../git/common/gitService';
10
11
export const ICodeSearchAuthenticationService = createServiceIdentifier<ICodeSearchAuthenticationService>('ICodeSearchAuthentication');
12
13
export interface ICodeSearchAuthenticationService {
14
readonly _serviceBrand: undefined;
15
16
tryAuthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void>;
17
tryReauthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void>;
18
19
promptForExpandedLocalIndexing(fileCount: number): Promise<boolean>;
20
}
21
22
export class BasicCodeSearchAuthenticationService implements ICodeSearchAuthenticationService {
23
24
declare readonly _serviceBrand: undefined;
25
26
constructor(
27
@IAuthenticationService private readonly _authenticationService: IAuthenticationService,
28
) { }
29
30
async tryAuthenticating(remoteInfo: ResolvedRepoRemoteInfo | undefined): Promise<void> {
31
if (remoteInfo?.repoId?.type === 'ado') {
32
await this._authenticationService.getAdoAccessTokenBase64({ createIfNone: true });
33
return;
34
}
35
36
await this._authenticationService.getGitHubSession('any', { createIfNone: { detail: l10n.t('Sign in to GitHub to use remote code search.') } });
37
}
38
39
async tryReauthenticating(remoteInfo: ResolvedRepoRemoteInfo | undefined): Promise<void> {
40
if (remoteInfo?.repoId?.type === 'ado') {
41
await this._authenticationService.getAdoAccessTokenBase64({ createIfNone: true });
42
return;
43
}
44
45
await this._authenticationService.getGitHubSession('permissive', { createIfNone: { detail: l10n.t('Sign in to GitHub with additional permissions for remote code search.') } });
46
}
47
48
async promptForExpandedLocalIndexing(fileCount: number): Promise<boolean> {
49
// Can't show prompt here
50
return false;
51
}
52
}
53