Skip to content

Commit 9e52154

Browse files
authored
Allow getting edit sessions by ref (microsoft#152116)
1 parent 008143b commit 9e52154

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class SessionSyncContribution extends Disposable implements IWorkbenchCon
123123
}
124124

125125
async applyEditSession() {
126-
const editSession = await this.sessionSyncWorkbenchService.read();
126+
const editSession = await this.sessionSyncWorkbenchService.read(undefined);
127127
if (!editSession) {
128128
return;
129129
}

src/vs/workbench/services/sessionSync/browser/sessionSyncWorkbenchService.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,30 @@ export class SessionSyncWorkbenchService extends Disposable implements ISessionS
7171
}
7272

7373
/**
74+
* @param ref: A specific content ref to retrieve content for, if it exists.
75+
* If undefined, this method will return the latest saved edit session, if any.
7476
*
75-
* @returns An object representing the latest saved edit session state, if any.
77+
* @returns An object representing the requested or latest edit session state, if any.
7678
*/
77-
async read(): Promise<EditSession | undefined> {
79+
async read(ref: string | undefined): Promise<EditSession | undefined> {
7880
this.initialized = await this.waitAndInitialize();
7981
if (!this.initialized) {
8082
throw new Error('Please sign in to apply your latest edit session.');
8183
}
8284

83-
// Pull latest session data from service
84-
const sessionData = await this.storeClient?.read('editSessions', null);
85-
if (!sessionData?.content) {
86-
return;
85+
let content: string | undefined | null;
86+
try {
87+
if (ref !== undefined) {
88+
content = await this.storeClient?.resolveContent('editSessions', ref);
89+
} else {
90+
content = (await this.storeClient?.read('editSessions', null))?.content;
91+
}
92+
} catch (ex) {
93+
this.logService.error(ex);
8794
}
8895

8996
// TODO@joyceerhl Validate session data, check schema version
90-
return JSON.parse(sessionData.content);
97+
return (content !== undefined && content !== null) ? JSON.parse(content) : undefined;
9198
}
9299

93100
/**

src/vs/workbench/services/sessionSync/common/sessionSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const ISessionSyncWorkbenchService = createDecorator<ISessionSyncWorkbenc
1212
export interface ISessionSyncWorkbenchService {
1313
_serviceBrand: undefined;
1414

15-
read(): Promise<EditSession | undefined>;
15+
read(ref: string | undefined): Promise<EditSession | undefined>;
1616
write(editSession: EditSession): Promise<void>;
1717
}
1818

0 commit comments

Comments
 (0)