Skip to content

Commit

Permalink
Merge pull request #162106 from microsoft/dev/joyceerhl/written-condor
Browse files Browse the repository at this point in the history
Various Edit Sessions fixes
  • Loading branch information
joyceerhl authored Sep 28, 2022
2 parents 7b7f5a0 + 689cfc7 commit 835d39c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
this._register(this.fileService.registerProvider(EditSessionsFileSystemProvider.SCHEMA, new EditSessionsFileSystemProvider(this.editSessionsStorageService)));
this.lifecycleService.onWillShutdown((e) => e.join(this.autoStoreEditSession(), { id: 'autoStoreEditSession', label: localize('autoStoreEditSession', 'Storing current edit session...') }));
this._register(this.editSessionsStorageService.onDidSignIn(() => this.updateAccountsMenuBadge()));
this._register(this.editSessionsStorageService.onDidSignOut(() => this.updateAccountsMenuBadge()));
}

private autoResumeEditSession() {
Expand Down Expand Up @@ -377,6 +378,10 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo

this.logService.info(ref !== undefined ? `Resuming edit session with ref ${ref}...` : 'Resuming edit session...');

if (silent && !(await this.editSessionsStorageService.initialize(false, true))) {
return;
}

const data = await this.editSessionsStorageService.read(ref);
if (!data) {
if (ref === undefined && !silent) {
Expand All @@ -397,6 +402,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo

try {
const { changes, conflictingChanges } = await this.generateChanges(editSession, ref);
if (changes.length === 0) {
return;
}

// TODO@joyceerhl Provide the option to diff files which would be overwritten by edit session contents
if (conflictingChanges.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return this._didSignIn.event;
}

private _didSignOut = new Emitter<void>();
get onDidSignOut() {
return this._didSignOut.event;
}

constructor(
@IFileService private readonly fileService: IFileService,
@IStorageService private readonly storageService: IStorageService,
Expand Down Expand Up @@ -162,11 +167,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return [];
}

public async initialize(fromContinueOn: boolean) {
public async initialize(fromContinueOn: boolean, silent: boolean = false) {
if (this.initialized) {
return true;
}
this.initialized = await this.doInitialize(fromContinueOn);
this.initialized = await this.doInitialize(fromContinueOn, silent);
this.signedInContext.set(this.initialized);
if (this.initialized) {
this._didSignIn.fire();
Expand All @@ -181,7 +186,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
* meaning that authentication is configured and it
* can be used to communicate with the remote storage service
*/
private async doInitialize(fromContinueOn: boolean): Promise<boolean> {
private async doInitialize(fromContinueOn: boolean, silent: boolean): Promise<boolean> {
// Wait for authentication extensions to be registered
await this.extensionService.whenInstalledExtensionsRegistered();

Expand All @@ -206,7 +211,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return true;
}

const authenticationSession = await this.getAuthenticationSession(fromContinueOn);
const authenticationSession = await this.getAuthenticationSession(fromContinueOn, silent);
if (authenticationSession !== undefined) {
this.#authenticationInfo = authenticationSession;
this.storeClient.setAuthToken(authenticationSession.token, authenticationSession.providerId);
Expand Down Expand Up @@ -239,14 +244,16 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
return currentMachineId;
}

private async getAuthenticationSession(fromContinueOn: boolean) {
private async getAuthenticationSession(fromContinueOn: boolean, silent: boolean) {
// If the user signed in previously and the session is still available, reuse that without prompting the user again
if (this.existingSessionId) {
this.logService.info(`Searching for existing authentication session with ID ${this.existingSessionId}`);
const existingSession = await this.getExistingSession();
if (existingSession) {
this.logService.info(`Found existing authentication session with ID ${existingSession.session.id}`);
return { sessionId: existingSession.session.id, token: existingSession.session.idToken ?? existingSession.session.accessToken, providerId: existingSession.session.providerId };
} else {
this._didSignOut.fire();
}
}

Expand All @@ -261,6 +268,12 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
}
}

// If we aren't supposed to prompt the user because
// we're in a silent flow, just return here
if (silent) {
return;
}

// Ask the user to pick a preferred account
const authenticationSession = await this.getAccountPreference(fromContinueOn);
if (authenticationSession !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class EditSessionDataViewDataProvider implements ITreeViewDataProvider {
const sessionData = await this.editSessionsStorageService.read(session.ref);
const label = sessionData?.editSession.folders.map((folder) => folder.name).join(', ') ?? session.ref;
const machineId = sessionData?.editSession.machine;
const description = machineId === undefined ? fromNow(session.created, true) : `${fromNow(session.created, true)}\u00a0\u00a0\u2022\u00a0\u00a0${await this.editSessionsStorageService.getMachineById(machineId)}`;
const machineName = machineId ? await this.editSessionsStorageService.getMachineById(machineId) : undefined;
const description = machineName === undefined ? fromNow(session.created, true) : `${fromNow(session.created, true)}\u00a0\u00a0\u2022\u00a0\u00a0${machineName}`;

editSessions.push({
handle: resource.toString(),
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/editSessions/common/editSessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export interface IEditSessionsStorageService {

readonly isSignedIn: boolean;
readonly onDidSignIn: Event<void>;
readonly onDidSignOut: Event<void>;

initialize(fromContinueOn: boolean): Promise<boolean>;
initialize(fromContinueOn: boolean, silent?: boolean): Promise<boolean>;
read(ref: string | undefined): Promise<{ ref: string; editSession: EditSession } | undefined>;
write(editSession: EditSession): Promise<string>;
delete(ref: string | null): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ suite('Edit session sync', () => {
instantiationService.stub(INotificationService, new TestNotificationService());
instantiationService.stub(IEditSessionsStorageService, new class extends mock<IEditSessionsStorageService>() {
override onDidSignIn = Event.None;
override onDidSignOut = Event.None;
});
instantiationService.stub(IProgressService, ProgressService);
instantiationService.stub(ISCMService, SCMService);
Expand Down

0 comments on commit 835d39c

Please sign in to comment.