Skip to content

Commit 1b6ce58

Browse files
authored
Debt - Add execution id to edit session request headers (microsoft#154575)
Add execution id to edit session request headers
1 parent b62b538 commit 1b6ce58

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

src/vs/platform/userDataSync/common/userDataSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export interface IUserDataSyncStoreClient {
184184
delete(resource: ServerResource, ref: string | null): Promise<void>;
185185

186186
getAllRefs(resource: ServerResource): Promise<IResourceRefHandle[]>;
187-
resolveContent(resource: ServerResource, ref: string): Promise<string | null>;
187+
resolveContent(resource: ServerResource, ref: string, headers?: IHeaders): Promise<string | null>;
188188
}
189189

190190
export const IUserDataSyncStoreService = createDecorator<IUserDataSyncStoreService>('IUserDataSyncStoreService');

src/vs/platform/userDataSync/common/userDataSyncStoreService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
244244
return result.map(({ url, created }) => ({ ref: relativePath(uri, uri.with({ path: url }))!, created: created * 1000 /* Server returns in seconds */ }));
245245
}
246246

247-
async resolveContent(resource: ServerResource, ref: string): Promise<string | null> {
247+
async resolveContent(resource: ServerResource, ref: string, headers: IHeaders = {}): Promise<string | null> {
248248
if (!this.userDataSyncStoreUrl) {
249249
throw new Error('No settings sync store url configured.');
250250
}
251251

252252
const url = joinPath(this.userDataSyncStoreUrl, 'resource', resource, ref).toString();
253-
const headers: IHeaders = {};
253+
headers = { ...headers };
254254
headers['Cache-Control'] = 'no-cache';
255255

256256
const context = await this.request(url, { type: 'GET', headers }, [], CancellationToken.None);

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
8585
super();
8686

8787
if (this.environmentService.editSessionId !== undefined) {
88-
void this.applyEditSession(this.environmentService.editSessionId).finally(() => this.environmentService.editSessionId = undefined);
88+
void this.resumeEditSession(this.environmentService.editSessionId).finally(() => this.environmentService.editSessionId = undefined);
8989
}
9090

9191
this.configurationService.onDidChangeConfiguration((e) => {
@@ -132,7 +132,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
132132

133133
this.registerContinueEditSessionAction();
134134

135-
this.registerApplyLatestEditSessionAction();
135+
this.registerResumeLatestEditSessionAction();
136136
this.registerStoreLatestEditSessionAction();
137137

138138
this.registerContinueInLocalFolderAction();
@@ -171,9 +171,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
171171
}));
172172
}
173173

174-
private registerApplyLatestEditSessionAction(): void {
174+
private registerResumeLatestEditSessionAction(): void {
175175
const that = this;
176-
this._register(registerAction2(class ApplyLatestEditSessionAction extends Action2 {
176+
this._register(registerAction2(class ResumeLatestEditSessionAction extends Action2 {
177177
constructor() {
178178
super({
179179
id: 'workbench.experimental.editSessions.actions.resumeLatest',
@@ -186,8 +186,8 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
186186
async run(accessor: ServicesAccessor): Promise<void> {
187187
await that.progressService.withProgress({
188188
location: ProgressLocation.Notification,
189-
title: localize('applying edit session', 'Applying edit session...')
190-
}, async () => await that.applyEditSession());
189+
title: localize('resuming edit session', 'Resuming edit session...')
190+
}, async () => await that.resumeEditSession());
191191
}
192192
}));
193193
}
@@ -213,26 +213,24 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
213213
}));
214214
}
215215

216-
async applyEditSession(ref?: string): Promise<void> {
217-
if (ref !== undefined) {
218-
this.logService.info(`Applying edit session with ref ${ref}.`);
219-
}
216+
async resumeEditSession(ref?: string): Promise<void> {
217+
this.logService.info(ref !== undefined ? `Resuming edit session with ref ${ref}...` : 'Resuming edit session...');
220218

221219
const data = await this.editSessionsWorkbenchService.read(ref);
222220
if (!data) {
223221
if (ref === undefined) {
224-
this.notificationService.info(localize('no edit session', 'There are no edit sessions to apply.'));
222+
this.notificationService.info(localize('no edit session', 'There are no edit sessions to resume.'));
225223
} else {
226-
this.notificationService.warn(localize('no edit session content for ref', 'Could not apply edit session contents for ID {0}.', ref));
224+
this.notificationService.warn(localize('no edit session content for ref', 'Could not resume edit session contents for ID {0}.', ref));
227225
}
228-
this.logService.info(`Aborting applying edit session as no edit session content is available to be applied from ref ${ref}.`);
226+
this.logService.info(`Aborting resuming edit session as no edit session content is available to be applied from ref ${ref}.`);
229227
return;
230228
}
231229
const editSession = data.editSession;
232230
ref = data.ref;
233231

234232
if (editSession.version > EditSessionSchemaVersion) {
235-
this.notificationService.error(localize('client too old', "Please upgrade to a newer version of {0} to apply this edit session.", this.productService.nameLong));
233+
this.notificationService.error(localize('client too old', "Please upgrade to a newer version of {0} to resume this edit session.", this.productService.nameLong));
236234
return;
237235
}
238236

@@ -266,7 +264,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
266264
if (hasLocalUncommittedChanges) {
267265
// TODO@joyceerhl Provide the option to diff files which would be overwritten by edit session contents
268266
const result = await this.dialogService.confirm({
269-
message: localize('apply edit session warning', 'Applying your edit session may overwrite your existing uncommitted changes. Do you want to proceed?'),
267+
message: localize('resume edit session warning', 'Resuming your edit session may overwrite your existing uncommitted changes. Do you want to proceed?'),
270268
type: 'warning',
271269
title: EDIT_SESSION_SYNC_CATEGORY.value
272270
});
@@ -287,8 +285,8 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
287285
await this.editSessionsWorkbenchService.delete(ref);
288286
this.logService.info(`Deleted edit session with ref ${ref}.`);
289287
} catch (ex) {
290-
this.logService.error('Failed to apply edit session, reason: ', (ex as Error).toString());
291-
this.notificationService.error(localize('apply failed', "Failed to apply your edit session."));
288+
this.logService.error('Failed to resume edit session, reason: ', (ex as Error).toString());
289+
this.notificationService.error(localize('resume failed', "Failed to resume your edit session."));
292290
}
293291
}
294292

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import { IProductService } from 'vs/platform/product/common/productService';
1414
import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
1515
import { IRequestService } from 'vs/platform/request/common/request';
1616
import { IStorageService, IStorageValueChangeEvent, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
17-
import { IAuthenticationProvider } from 'vs/platform/userDataSync/common/userDataSync';
17+
import { createSyncHeaders, IAuthenticationProvider } from 'vs/platform/userDataSync/common/userDataSync';
1818
import { UserDataSyncStoreClient } from 'vs/platform/userDataSync/common/userDataSyncStoreService';
1919
import { AuthenticationSession, AuthenticationSessionsChangeEvent, IAuthenticationService } from 'vs/workbench/services/authentication/common/authentication';
2020
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2121
import { EDIT_SESSIONS_SIGNED_IN, EditSession, EDIT_SESSION_SYNC_CATEGORY, IEditSessionsWorkbenchService, EDIT_SESSIONS_SIGNED_IN_KEY, IEditSessionsLogService } from 'vs/workbench/contrib/editSessions/common/editSessions';
22+
import { generateUuid } from 'vs/base/common/uuid';
2223

2324
type ExistingSession = IQuickPickItem & { session: AuthenticationSession & { providerId: string } };
2425
type AuthenticationProviderOption = IQuickPickItem & { provider: IAuthenticationProvider };
@@ -73,7 +74,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
7374
throw new Error('Please sign in to store your edit session.');
7475
}
7576

76-
return this.storeClient!.write('editSessions', JSON.stringify(editSession), null);
77+
return this.storeClient!.write('editSessions', JSON.stringify(editSession), null, createSyncHeaders(generateUuid()));
7778
}
7879

7980
/**
@@ -89,11 +90,12 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
8990
}
9091

9192
let content: string | undefined | null;
93+
const headers = createSyncHeaders(generateUuid());
9294
try {
9395
if (ref !== undefined) {
94-
content = await this.storeClient?.resolveContent('editSessions', ref);
96+
content = await this.storeClient?.resolveContent('editSessions', ref, headers);
9597
} else {
96-
const result = await this.storeClient?.read('editSessions', null);
98+
const result = await this.storeClient?.read('editSessions', null, headers);
9799
content = result?.content;
98100
ref = result?.ref;
99101
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ suite('Edit session sync', () => {
112112
// Create root folder
113113
await fileService.createFolder(folderUri);
114114

115-
// Apply edit session
116-
await editSessionsContribution.applyEditSession();
115+
// Resume edit session
116+
await editSessionsContribution.resumeEditSession();
117117

118118
// Verify edit session was correctly applied
119119
assert.equal((await fileService.readFile(fileUri)).value.toString(), fileContents);

0 commit comments

Comments
 (0)