@@ -85,6 +85,7 @@ export async function checkChangedOnServer(file: CurrentTextFile | CurrentBinary
8585// Synchronize the client version and the server version of the same file
8686export async function importFile (
8787 file : CurrentTextFile | CurrentBinaryFile ,
88+ willCompile : boolean ,
8889 ignoreConflict ?: boolean ,
8990 skipDeplCheck = false
9091) : Promise < any > {
@@ -128,7 +129,7 @@ export async function importFile(
128129 ignoreConflict
129130 ) ;
130131 workspaceState . update ( `${ file . uniqueId } :mtime` , Number ( new Date ( data . result . ts + "Z" ) ) ) ;
131- if ( data . result . flags === 1 ) {
132+ if ( data . result . flags === 1 && ! willCompile ) {
132133 // If flags === 1, putDoc returns new Storage definitions and the file must be a CLS
133134 const oldContent = new TextDecoder ( "utf-8" ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) ;
134135 const oldContentArray = oldContent . split ( / \r ? \n / g) ;
@@ -180,7 +181,7 @@ What do you want to do?`,
180181 // Clear cache entry
181182 workspaceState . update ( `${ file . uniqueId } :mtime` , undefined ) ;
182183 // Overwrite
183- return importFile ( file , true , true ) ;
184+ return importFile ( file , willCompile , true , true ) ;
184185 case "Pull Server Changes" :
185186 loadChanges ( [ file ] ) ;
186187 return Promise . reject ( ) ;
@@ -384,14 +385,16 @@ export async function importAndCompile(document?: vscode.TextDocument, askFlags
384385 return ;
385386 }
386387
387- return (
388- importFile ( file )
389- . then ( ( ) => {
390- if ( isCompilable ( file . name ) ) compile ( [ file ] , askFlags ) ;
391- } )
392- // importFile handles any server errors
393- . catch ( ( ) => { } )
394- ) ;
388+ try {
389+ if ( isCompilable ( file . name ) ) {
390+ await importFile ( file , true ) ;
391+ compile ( [ file ] , askFlags ) ;
392+ } else {
393+ await importFile ( file , false ) ;
394+ }
395+ } catch ( _ ) {
396+ // importFile handles any server errors
397+ }
395398}
396399
397400export async function compileOnly ( document ?: vscode . TextDocument , askFlags = false ) : Promise < any > {
@@ -461,28 +464,26 @@ async function importFiles(files: vscode.Uri[], noCompile = false) {
461464 await Promise . allSettled < void > (
462465 files . map ( ( uri ) =>
463466 rateLimiter . call ( async ( ) => {
464- return vscode . workspace . fs
465- . readFile ( uri )
466- . then ( ( contentBytes ) =>
467- currentFileFromContent (
468- uri ,
469- isText ( uri . path . split ( "/" ) . pop ( ) , Buffer . from ( contentBytes ) )
470- ? new TextDecoder ( ) . decode ( contentBytes )
471- : Buffer . from ( contentBytes )
472- )
473- )
474- . then ( ( curFile ) => {
475- if ( curFile ) {
476- if ( typeof curFile . content == "string" && isCompilable ( curFile . name ) ) toCompile . push ( curFile ) ;
477- return importFile ( curFile ) . then ( ( ) => outputChannel . appendLine ( "Imported file: " + curFile . fileName ) ) ;
478- }
479- } ) ;
467+ const contentBytes = await vscode . workspace . fs . readFile ( uri ) ;
468+ const curFile = currentFileFromContent (
469+ uri ,
470+ isText ( uri . path . split ( "/" ) . pop ( ) , Buffer . from ( contentBytes ) )
471+ ? new TextDecoder ( ) . decode ( contentBytes )
472+ : Buffer . from ( contentBytes )
473+ ) ;
474+ if ( curFile ) {
475+ if ( typeof curFile . content == "string" && isCompilable ( curFile . name ) ) {
476+ toCompile . push ( curFile ) ;
477+ }
478+ await importFile ( curFile , ! noCompile ) ;
479+ outputChannel . appendLine ( "Imported file: " + curFile . fileName ) ;
480+ }
480481 } )
481482 )
482483 ) ;
483484
484485 if ( ! noCompile && toCompile . length > 0 ) {
485- return compile ( toCompile ) ;
486+ await compile ( toCompile ) ;
486487 }
487488 return ;
488489}
0 commit comments