Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/remoteCodeSearch/vscode-node/codeSearchRepoAuth.ts
13401 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 { t } from '@vscode/l10n';
7
import * as vscode from 'vscode';
8
import { IAuthenticationService } from '../../authentication/common/authentication';
9
import { IAuthenticationChatUpgradeService } from '../../authentication/common/authenticationUpgrade';
10
import { ResolvedRepoRemoteInfo } from '../../git/common/gitService';
11
import { ICodeSearchAuthenticationService } from '../node/codeSearchRepoAuth';
12
13
14
export class VsCodeCodeSearchAuthenticationService implements ICodeSearchAuthenticationService {
15
16
declare readonly _serviceBrand: undefined;
17
18
constructor(
19
@IAuthenticationService private readonly _authService: IAuthenticationService,
20
@IAuthenticationChatUpgradeService private readonly _authUpgradeService: IAuthenticationChatUpgradeService,
21
) { }
22
23
async tryAuthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void> {
24
const fetchUrl = repo?.fetchUrl;
25
26
const signInButton: vscode.MessageItem = {
27
title: t`Sign In`,
28
};
29
const cancelButton: vscode.MessageItem = {
30
title: t`Cancel`,
31
isCloseAffordance: true
32
};
33
34
if (repo?.repoId.type === 'ado') {
35
const result = await vscode.window.showWarningMessage(t`Sign in to use remote index`, {
36
modal: true,
37
detail: fetchUrl
38
? t`Sign in to Azure DevOps to use remote workspace index for: ${fetchUrl.toString()}`
39
: t`Sign in to Azure DevOps to use remote workspace index for a repo in this workspace`
40
}, signInButton, cancelButton);
41
42
if (result === signInButton) {
43
await this._authService.getAdoAccessTokenBase64({ createIfNone: true });
44
return;
45
}
46
} else {
47
const result = await vscode.window.showWarningMessage(t`Sign in to use remote index`, {
48
modal: true,
49
detail: fetchUrl
50
? t`Sign in to GitHub to use remote workspace index for: ${fetchUrl.toString()}`
51
: t`Sign in to GitHub to use remote workspace index for a repo in this workspace`
52
}, signInButton, cancelButton);
53
54
if (result === signInButton) {
55
await this._authService.getGitHubSession('any', { createIfNone: { detail: t('Sign in to GitHub to use remote workspace index.') } });
56
return;
57
}
58
}
59
}
60
61
async tryReauthenticating(repo: ResolvedRepoRemoteInfo | undefined): Promise<void> {
62
const fetchUrl = repo?.fetchUrl;
63
64
const signInButton: vscode.MessageItem = {
65
title: t`Sign In`,
66
};
67
const cancelButton: vscode.MessageItem = {
68
title: t`Cancel`,
69
isCloseAffordance: true
70
};
71
72
if (repo?.repoId.type === 'ado') {
73
const result = await vscode.window.showWarningMessage(t`Reauthenticate to use remote workspace index`, {
74
modal: true,
75
detail: fetchUrl
76
? t`Sign in to Azure DevOps again to use remote workspace index for: ${fetchUrl}`
77
: t`Sign in to Azure DevOps again to use remote workspace index for a repo in this workspace`
78
}, signInButton, cancelButton);
79
80
if (result === signInButton) {
81
await this._authService.getAdoAccessTokenBase64({ createIfNone: true });
82
return;
83
}
84
} else {
85
const result = await vscode.window.showWarningMessage(t`Reauthenticate to use remote workspace index`, {
86
modal: true,
87
detail: fetchUrl
88
? t`Sign in to GitHub again to use remote workspace index for: ${fetchUrl}`
89
: t`Sign in to GitHub again to use remote workspace index for a repo in this workspace`
90
}, signInButton, cancelButton);
91
92
if (result === signInButton) {
93
await this._authUpgradeService.showPermissiveSessionModal();
94
return;
95
}
96
}
97
}
98
99
async promptForExpandedLocalIndexing(fileCount: number): Promise<boolean> {
100
const confirmButton: vscode.MessageItem = {
101
title: t`Enable`,
102
};
103
const cancelButton: vscode.MessageItem = {
104
title: t`Cancel`,
105
isCloseAffordance: true
106
};
107
108
const result = await vscode.window.showWarningMessage(
109
t`Build local index for this workspace?`,
110
{
111
modal: true,
112
detail: t`This workspace contains ${fileCount} files. Building a local index may take a while but will improve search performance.`,
113
},
114
confirmButton,
115
cancelButton
116
);
117
118
return result === confirmButton;
119
}
120
}
121