Skip to content

Commit 835d39c

Browse files
authored
Merge pull request microsoft#162106 from microsoft/dev/joyceerhl/written-condor
Various Edit Sessions fixes
2 parents 7b7f5a0 + 689cfc7 commit 835d39c

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
131131
this._register(this.fileService.registerProvider(EditSessionsFileSystemProvider.SCHEMA, new EditSessionsFileSystemProvider(this.editSessionsStorageService)));
132132
this.lifecycleService.onWillShutdown((e) => e.join(this.autoStoreEditSession(), { id: 'autoStoreEditSession', label: localize('autoStoreEditSession', 'Storing current edit session...') }));
133133
this._register(this.editSessionsStorageService.onDidSignIn(() => this.updateAccountsMenuBadge()));
134+
this._register(this.editSessionsStorageService.onDidSignOut(() => this.updateAccountsMenuBadge()));
134135
}
135136

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

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

381+
if (silent && !(await this.editSessionsStorageService.initialize(false, true))) {
382+
return;
383+
}
384+
380385
const data = await this.editSessionsStorageService.read(ref);
381386
if (!data) {
382387
if (ref === undefined && !silent) {
@@ -397,6 +402,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
397402

398403
try {
399404
const { changes, conflictingChanges } = await this.generateChanges(editSession, ref);
405+
if (changes.length === 0) {
406+
return;
407+
}
400408

401409
// TODO@joyceerhl Provide the option to diff files which would be overwritten by edit session contents
402410
if (conflictingChanges.length > 0) {

src/vs/workbench/contrib/editSessions/browser/editSessionsStorageService.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
5656
return this._didSignIn.event;
5757
}
5858

59+
private _didSignOut = new Emitter<void>();
60+
get onDidSignOut() {
61+
return this._didSignOut.event;
62+
}
63+
5964
constructor(
6065
@IFileService private readonly fileService: IFileService,
6166
@IStorageService private readonly storageService: IStorageService,
@@ -162,11 +167,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
162167
return [];
163168
}
164169

165-
public async initialize(fromContinueOn: boolean) {
170+
public async initialize(fromContinueOn: boolean, silent: boolean = false) {
166171
if (this.initialized) {
167172
return true;
168173
}
169-
this.initialized = await this.doInitialize(fromContinueOn);
174+
this.initialized = await this.doInitialize(fromContinueOn, silent);
170175
this.signedInContext.set(this.initialized);
171176
if (this.initialized) {
172177
this._didSignIn.fire();
@@ -181,7 +186,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
181186
* meaning that authentication is configured and it
182187
* can be used to communicate with the remote storage service
183188
*/
184-
private async doInitialize(fromContinueOn: boolean): Promise<boolean> {
189+
private async doInitialize(fromContinueOn: boolean, silent: boolean): Promise<boolean> {
185190
// Wait for authentication extensions to be registered
186191
await this.extensionService.whenInstalledExtensionsRegistered();
187192

@@ -206,7 +211,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
206211
return true;
207212
}
208213

209-
const authenticationSession = await this.getAuthenticationSession(fromContinueOn);
214+
const authenticationSession = await this.getAuthenticationSession(fromContinueOn, silent);
210215
if (authenticationSession !== undefined) {
211216
this.#authenticationInfo = authenticationSession;
212217
this.storeClient.setAuthToken(authenticationSession.token, authenticationSession.providerId);
@@ -239,14 +244,16 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
239244
return currentMachineId;
240245
}
241246

242-
private async getAuthenticationSession(fromContinueOn: boolean) {
247+
private async getAuthenticationSession(fromContinueOn: boolean, silent: boolean) {
243248
// If the user signed in previously and the session is still available, reuse that without prompting the user again
244249
if (this.existingSessionId) {
245250
this.logService.info(`Searching for existing authentication session with ID ${this.existingSessionId}`);
246251
const existingSession = await this.getExistingSession();
247252
if (existingSession) {
248253
this.logService.info(`Found existing authentication session with ID ${existingSession.session.id}`);
249254
return { sessionId: existingSession.session.id, token: existingSession.session.idToken ?? existingSession.session.accessToken, providerId: existingSession.session.providerId };
255+
} else {
256+
this._didSignOut.fire();
250257
}
251258
}
252259

@@ -261,6 +268,12 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
261268
}
262269
}
263270

271+
// If we aren't supposed to prompt the user because
272+
// we're in a silent flow, just return here
273+
if (silent) {
274+
return;
275+
}
276+
264277
// Ask the user to pick a preferred account
265278
const authenticationSession = await this.getAccountPreference(fromContinueOn);
266279
if (authenticationSession !== undefined) {

src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ class EditSessionDataViewDataProvider implements ITreeViewDataProvider {
208208
const sessionData = await this.editSessionsStorageService.read(session.ref);
209209
const label = sessionData?.editSession.folders.map((folder) => folder.name).join(', ') ?? session.ref;
210210
const machineId = sessionData?.editSession.machine;
211-
const description = machineId === undefined ? fromNow(session.created, true) : `${fromNow(session.created, true)}\u00a0\u00a0\u2022\u00a0\u00a0${await this.editSessionsStorageService.getMachineById(machineId)}`;
211+
const machineName = machineId ? await this.editSessionsStorageService.getMachineById(machineId) : undefined;
212+
const description = machineName === undefined ? fromNow(session.created, true) : `${fromNow(session.created, true)}\u00a0\u00a0\u2022\u00a0\u00a0${machineName}`;
212213

213214
editSessions.push({
214215
handle: resource.toString(),

src/vs/workbench/contrib/editSessions/common/editSessions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export interface IEditSessionsStorageService {
2525

2626
readonly isSignedIn: boolean;
2727
readonly onDidSignIn: Event<void>;
28+
readonly onDidSignOut: Event<void>;
2829

29-
initialize(fromContinueOn: boolean): Promise<boolean>;
30+
initialize(fromContinueOn: boolean, silent?: boolean): Promise<boolean>;
3031
read(ref: string | undefined): Promise<{ ref: string; editSession: EditSession } | undefined>;
3132
write(editSession: EditSession): Promise<string>;
3233
delete(ref: string | null): Promise<void>;

src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ suite('Edit session sync', () => {
6868
instantiationService.stub(INotificationService, new TestNotificationService());
6969
instantiationService.stub(IEditSessionsStorageService, new class extends mock<IEditSessionsStorageService>() {
7070
override onDidSignIn = Event.None;
71+
override onDidSignOut = Event.None;
7172
});
7273
instantiationService.stub(IProgressService, ProgressService);
7374
instantiationService.stub(ISCMService, SCMService);

0 commit comments

Comments
 (0)