@@ -58,6 +58,16 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
5858 return this . _didSignOut . event ;
5959 }
6060
61+ private _lastWrittenResources = new Map < SyncResource , { ref : string ; content : string } > ( ) ;
62+ get lastWrittenResources ( ) {
63+ return this . _lastWrittenResources ;
64+ }
65+
66+ private _lastReadResources = new Map < SyncResource , { ref : string ; content : string } > ( ) ;
67+ get lastReadResources ( ) {
68+ return this . _lastReadResources ;
69+ }
70+
6171 storeClient : EditSessionsStoreClient | undefined ; // TODO@joyceerhl lifecycle hack
6272
6373 constructor (
@@ -89,9 +99,9 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
8999 }
90100
91101 /**
92- *
93- * @param editSession An object representing edit session state to be restored.
94- * @returns The ref of the stored edit session state.
102+ * @param resource: The resource to retrieve content for.
103+ * @param content An object representing resource state to be restored.
104+ * @returns The ref of the stored state.
95105 */
96106 async write ( resource : SyncResource , content : string | EditSession ) : Promise < string > {
97107 await this . initialize ( false ) ;
@@ -103,14 +113,20 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
103113 content . machine = await this . getOrCreateCurrentMachineId ( ) ;
104114 }
105115
106- return this . storeClient ! . writeResource ( resource , typeof content === 'string' ? content : JSON . stringify ( content ) , null , undefined , createSyncHeaders ( generateUuid ( ) ) ) ;
116+ content = typeof content === 'string' ? content : JSON . stringify ( content ) ;
117+ const ref = await this . storeClient ! . writeResource ( resource , content , null , undefined , createSyncHeaders ( generateUuid ( ) ) ) ;
118+
119+ this . _lastWrittenResources . set ( resource , { ref, content } ) ;
120+
121+ return ref ;
107122 }
108123
109124 /**
125+ * @param resource: The resource to retrieve content for.
110126 * @param ref: A specific content ref to retrieve content for, if it exists.
111127 * If undefined, this method will return the latest saved edit session, if any.
112128 *
113- * @returns An object representing the requested or latest edit session state, if any.
129+ * @returns An object representing the requested or latest state, if any.
114130 */
115131 async read ( resource : SyncResource , ref : string | undefined ) : Promise < { ref : string ; content : string } | undefined > {
116132 await this . initialize ( false ) ;
@@ -133,7 +149,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
133149 }
134150
135151 // TODO@joyceerhl Validate session data, check schema version
136- return ( content !== undefined && content !== null && ref !== undefined ) ? { ref, content } : undefined ;
152+ if ( content !== undefined && content !== null && ref !== undefined ) {
153+ this . _lastReadResources . set ( resource , { ref, content } ) ;
154+ return { ref, content } ;
155+ }
156+ return undefined ;
137157 }
138158
139159 async delete ( resource : SyncResource , ref : string | null ) {
0 commit comments