@@ -132,8 +132,9 @@ export async function importFile(
132132 if ( data . result . flags === 1 && ! willCompile ) {
133133 // If flags === 1, putDoc returns new Storage definitions and the file must be a CLS
134134 const oldContent = new TextDecoder ( "utf-8" ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) ;
135- const oldContentArray = oldContent . split ( / \r ? \n / g) ;
136- const newContentArray = updateStorage ( oldContentArray , data . result . content ) ;
135+ const oldContentArray = oldContent . split ( / \r ? \n / ) ;
136+ const storage = Buffer . isBuffer ( data . result . content ) ? new TextDecoder ( ) . decode ( data . result . content ) . split ( / \r ? \n / g) : data . result . content ;
137+ const newContentArray = updateStorage ( oldContentArray , storage ) ;
137138 if ( oldContentArray . some ( ( oldLine , index ) => oldLine !== newContentArray [ index ] ) ) {
138139 const EOL = ( ( < CurrentTextFile > file ) ?. eol ?? vscode . EndOfLine . LF ) == vscode . EndOfLine . CRLF ? "\r\n" : "\n" ;
139140 const newContent = newContentArray . join ( EOL ) ;
@@ -304,14 +305,15 @@ function storageToMap(storage: string[]): Map<string, string> {
304305 if ( line . startsWith ( "Storage " ) ) {
305306 k = line . slice ( "Storage " . length , line . length ) ;
306307 v = [ ] ;
307- } else if ( line === "{" ) {
308- continue ;
309- } else if ( line === "}" ) {
310- map . set ( k , v . join ( "\n" ) ) ;
311- } else if ( line === "" ) {
312- continue ;
313- } else {
314- v . push ( line ) ;
308+ } else if ( k !== undefined ) {
309+ if ( line === "{" ) {
310+ continue ;
311+ } else if ( line === "}" ) {
312+ map . set ( k , v . join ( "\n" ) ) ;
313+ k = undefined ;
314+ } else {
315+ v . push ( line ) ;
316+ }
315317 }
316318 }
317319 return map ;
@@ -392,7 +394,7 @@ export async function importAndCompile(document?: vscode.TextDocument, askFlags
392394 } else {
393395 await importFile ( file , false ) ;
394396 }
395- } catch ( _ ) {
397+ } catch {
396398 // importFile handles any server errors
397399 }
398400}
0 commit comments