mirror of
https://github.com/hanzoai/code.git
synced 2026-09-30 20:53:35 +00:00
rebase from vscode f35c3823
This commit is contained in:
@@ -18,7 +18,9 @@ interface SessionData {
|
||||
account?: {
|
||||
label?: string;
|
||||
displayName?: string;
|
||||
id: string;
|
||||
// Unfortunately, for some time the id was a number, so we need to support both.
|
||||
// This can be removed once we are confident that all users have migrated to the new id.
|
||||
id: string | number;
|
||||
};
|
||||
scopes: string[];
|
||||
accessToken: string;
|
||||
@@ -134,7 +136,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
return sessions;
|
||||
});
|
||||
|
||||
this._supportsMultipleAccounts = vscode.workspace.getConfiguration('github.experimental').get<boolean>('multipleAccounts', false);
|
||||
this._supportsMultipleAccounts = this._shouldSupportMultipleAccounts();
|
||||
|
||||
this._disposable = vscode.Disposable.from(
|
||||
this._telemetryReporter,
|
||||
@@ -142,7 +144,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
this.context.secrets.onDidChange(() => this.checkForUpdates()),
|
||||
vscode.workspace.onDidChangeConfiguration(async e => {
|
||||
if (e.affectsConfiguration('github.experimental.multipleAccounts')) {
|
||||
const newValue = vscode.workspace.getConfiguration('github.experimental').get<boolean>('multipleAccounts', false);
|
||||
const newValue = this._shouldSupportMultipleAccounts();
|
||||
if (newValue === this._supportsMultipleAccounts) {
|
||||
return;
|
||||
}
|
||||
@@ -239,9 +241,14 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
return [];
|
||||
}
|
||||
|
||||
// Unfortunately, we were using a number secretly for the account id for some time... this is due to a bad `any`.
|
||||
// AuthenticationSession's account id is a string, so we need to detect when there is a number accountId and re-store
|
||||
// the sessions to migrate away from the bad number usage.
|
||||
// TODO@TylerLeonhardt: Remove this after we are confident that all users have migrated to the new id.
|
||||
let seenNumberAccountId: boolean = false;
|
||||
// TODO: eventually remove this Set because we should only have one session per set of scopes.
|
||||
const scopesSeen = new Set<string>();
|
||||
const sessionPromises = sessionData.map(async (session: SessionData) => {
|
||||
const sessionPromises = sessionData.map(async (session: SessionData): Promise<vscode.AuthenticationSession | undefined> => {
|
||||
// For GitHub scope list, order doesn't matter so we immediately sort the scopes
|
||||
const scopesStr = [...session.scopes].sort().join(' ');
|
||||
if (!this._supportsMultipleAccounts && scopesSeen.has(scopesStr)) {
|
||||
@@ -262,13 +269,23 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
|
||||
this._logger.trace(`Read the following session from the keychain with the following scopes: ${scopesStr}`);
|
||||
scopesSeen.add(scopesStr);
|
||||
|
||||
let accountId: string;
|
||||
if (session.account?.id) {
|
||||
if (typeof session.account.id === 'number') {
|
||||
seenNumberAccountId = true;
|
||||
}
|
||||
accountId = `${session.account.id}`;
|
||||
} else {
|
||||
accountId = userInfo?.id ?? '<unknown>';
|
||||
}
|
||||
return {
|
||||
id: session.id,
|
||||
account: {
|
||||
label: session.account
|
||||
? session.account.label ?? session.account.displayName ?? '<unknown>'
|
||||
: userInfo?.accountName ?? '<unknown>',
|
||||
id: session.account?.id ?? userInfo?.id ?? '<unknown>'
|
||||
id: accountId
|
||||
},
|
||||
// we set this to session.scopes to maintain the original order of the scopes requested
|
||||
// by the extension that called getSession()
|
||||
@@ -283,7 +300,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
.filter(<T>(p?: T): p is T => Boolean(p));
|
||||
|
||||
this._logger.info(`Got ${verifiedSessions.length} verified sessions.`);
|
||||
if (verifiedSessions.length !== sessionData.length) {
|
||||
if (seenNumberAccountId || verifiedSessions.length !== sessionData.length) {
|
||||
await this.storeSessions(verifiedSessions);
|
||||
}
|
||||
|
||||
@@ -407,4 +424,26 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private _shouldSupportMultipleAccounts(): boolean {
|
||||
// First check if there is a setting value to allow user to override the default
|
||||
const inspect = vscode.workspace.getConfiguration('github.experimental').inspect<boolean>('multipleAccounts');
|
||||
if (inspect?.workspaceFolderValue !== undefined) {
|
||||
this._logger.trace(`Acquired multi-account enablement value from 'workspaceFolderValue'. Value: ${inspect.workspaceFolderValue}`);
|
||||
return inspect.workspaceFolderValue;
|
||||
}
|
||||
if (inspect?.workspaceValue !== undefined) {
|
||||
this._logger.trace(`Acquired multi-account enablement value from 'workspaceValue'. Value: ${inspect.workspaceValue}`);
|
||||
return inspect.workspaceValue;
|
||||
}
|
||||
if (inspect?.globalValue !== undefined) {
|
||||
this._logger.trace(`Acquired multi-account enablement value from 'globalValue'. Value: ${inspect.globalValue}`);
|
||||
return inspect.globalValue;
|
||||
}
|
||||
|
||||
const value = vscode.env.uriScheme !== 'vscode';
|
||||
this._logger.trace(`Acquired multi-account enablement value from default. Value: ${value} because of uriScheme: ${vscode.env.uriScheme}`);
|
||||
// If no setting or experiment value is found, default to false on stable and true on insiders
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user