@@ -24,6 +24,7 @@ import {
2424 exportedUris ,
2525 getWsFolder ,
2626 handleError ,
27+ isClass ,
2728 isClassDeployed ,
2829 isClassOrRtn ,
2930 isCompilable ,
@@ -37,6 +38,7 @@ import {
3738import { StudioActions } from "./studio" ;
3839import { NodeBase , PackageNode , RootNode } from "../explorer/nodes" ;
3940import { getUrisForDocument , updateIndex } from "../utils/documentIndex" ;
41+ import { Document } from "../api/atelier" ;
4042
4143/**
4244 * For files being locally edited, get and return its mtime timestamp from workspace-state cache if present there,
@@ -218,7 +220,32 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
218220 const mtime = Number ( new Date ( doc . ts + "Z" ) ) ;
219221 workspaceState . update ( `${ file . uniqueId } :mtime` , mtime > 0 ? mtime : undefined ) ;
220222 if ( notIsfs ( file . uri ) ) {
221- const content = await api . getDoc ( file . name , file . uri ) . then ( ( data ) => data . result . content ) ;
223+ let content : Document [ "content" ] ;
224+ if ( isClass ( file . uri . path ) ) {
225+ // Insert/update the storage part of class definition.
226+ content = new TextDecoder ( 'utf-8' ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) . split ( / \r ? \n / g) ;
227+ let storageBegin = - 1 ;
228+ let storageEnd = - 1 ;
229+ let classEnd ;
230+ for ( let i = 0 ; i < content . length ; i ++ ) {
231+ if ( content [ i ] . startsWith ( "<Storage " ) ) {
232+ storageBegin = i ;
233+ } else if ( content [ i ] . startsWith ( "</Storage>" ) ) {
234+ storageEnd = i ;
235+ } else if ( content [ i ] . startsWith ( "}" ) ) {
236+ classEnd = i ;
237+ }
238+ }
239+ let storage = ( await api . getDoc ( file . name , file . uri , undefined , true ) ) . result . content ;
240+ storage = Buffer . isBuffer ( storage ) ? new TextDecoder ( ) . decode ( storage ) . split ( / \r ? \n / g) : storage ;
241+ if ( ( 0 <= storageBegin ) && ( storageBegin < storageEnd ) ) {
242+ content . splice ( storageBegin , storageEnd - storageEnd , ...storage )
243+ } else {
244+ content . splice ( classEnd , 0 , ...storage )
245+ }
246+ } else {
247+ content = ( await api . getDoc ( file . name , file . uri ) ) . result . content ;
248+ }
222249 exportedUris . add ( file . uri . toString ( ) ) ; // Set optimistically
223250 await vscode . workspace . fs
224251 . writeFile (
0 commit comments