@@ -58,6 +58,16 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
58
58
return this . _didSignOut . event ;
59
59
}
60
60
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
+
61
71
storeClient : EditSessionsStoreClient | undefined ; // TODO@joyceerhl lifecycle hack
62
72
63
73
constructor (
@@ -89,9 +99,9 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
89
99
}
90
100
91
101
/**
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.
95
105
*/
96
106
async write ( resource : SyncResource , content : string | EditSession ) : Promise < string > {
97
107
await this . initialize ( false ) ;
@@ -103,14 +113,20 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
103
113
content . machine = await this . getOrCreateCurrentMachineId ( ) ;
104
114
}
105
115
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 ;
107
122
}
108
123
109
124
/**
125
+ * @param resource: The resource to retrieve content for.
110
126
* @param ref: A specific content ref to retrieve content for, if it exists.
111
127
* If undefined, this method will return the latest saved edit session, if any.
112
128
*
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.
114
130
*/
115
131
async read ( resource : SyncResource , ref : string | undefined ) : Promise < { ref : string ; content : string } | undefined > {
116
132
await this . initialize ( false ) ;
@@ -133,7 +149,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
133
149
}
134
150
135
151
// 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 ;
137
157
}
138
158
139
159
async delete ( resource : SyncResource , ref : string | null ) {
0 commit comments