@@ -19,7 +19,6 @@ import {
1919 cspAppsForUri ,
2020 CurrentBinaryFile ,
2121 currentFile ,
22- CurrentFile ,
2322 currentFileFromContent ,
2423 CurrentTextFile ,
2524 exportedUris ,
@@ -231,7 +230,16 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
231230 const content = await api . getDoc ( file . name , file . uri ) . then ( ( data ) => data . result . content ) ;
232231 exportedUris . add ( file . uri . toString ( ) ) ; // Set optimistically
233232 await vscode . workspace . fs
234- . writeFile ( file . uri , Buffer . isBuffer ( content ) ? content : new TextEncoder ( ) . encode ( content . join ( "\n" ) ) )
233+ . writeFile (
234+ file . uri ,
235+ Buffer . isBuffer ( content )
236+ ? content
237+ : new TextEncoder ( ) . encode (
238+ content . join (
239+ ( ( < CurrentTextFile > file ) ?. eol ?? vscode . EndOfLine . LF ) == vscode . EndOfLine . CRLF ? "\r\n" : "\n"
240+ )
241+ )
242+ )
235243 . then ( undefined , ( e ) => {
236244 // Save failed, so remove this URI from the set
237245 exportedUris . delete ( file . uri . toString ( ) ) ;
@@ -251,12 +259,15 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
251259 ) ;
252260}
253261
254- export async function compile ( docs : CurrentFile [ ] , flags ?: string ) : Promise < any > {
262+ export async function compile ( docs : ( CurrentTextFile | CurrentBinaryFile ) [ ] , flags ?: string ) : Promise < any > {
255263 const wsFolder = vscode . workspace . getWorkspaceFolder ( docs [ 0 ] . uri ) ;
256264 const conf = vscode . workspace . getConfiguration ( "objectscript" , wsFolder || docs [ 0 ] . uri ) ;
257265 flags = flags || conf . get ( "compileFlags" ) ;
258266 const api = new AtelierAPI ( docs [ 0 ] . uri ) ;
259267 const docNames = docs . map ( ( d ) => d . name ) ;
268+ // Determine the line ending to use for other documents affected
269+ // by compilation so we don't need to read their contents
270+ const eol = ( < CurrentTextFile > docs . find ( ( d ) => ( < CurrentTextFile > d ) ?. eol ) ) ?. eol ?? vscode . EndOfLine . LF ;
260271 return vscode . window
261272 . withProgress (
262273 {
@@ -284,9 +295,11 @@ export async function compile(docs: CurrentFile[], flags?: string): Promise<any>
284295 name : f . name ,
285296 uri : u ,
286297 uniqueId : `${ wsFolder . name } :${ f . name } ` ,
287- // These two keys aren't used by loadChanges()
298+ eol,
299+ // These three keys aren't used by loadChanges()
288300 workspaceFolder : wsFolder . name ,
289301 fileName : u . fsPath ,
302+ content : "" ,
290303 } ) ;
291304 } ) ;
292305 } ) ;
@@ -416,7 +429,7 @@ export async function namespaceCompile(askFlags = false): Promise<any> {
416429}
417430
418431async function importFiles ( files : vscode . Uri [ ] , noCompile = false ) {
419- const toCompile : CurrentFile [ ] = [ ] ;
432+ const toCompile : ( CurrentTextFile | CurrentBinaryFile ) [ ] = [ ] ;
420433 const rateLimiter = new RateLimiter ( 50 ) ;
421434 await Promise . allSettled < void > (
422435 files . map ( ( uri ) =>
0 commit comments