@@ -19,7 +19,6 @@ import {
19
19
cspAppsForUri ,
20
20
CurrentBinaryFile ,
21
21
currentFile ,
22
- CurrentFile ,
23
22
currentFileFromContent ,
24
23
CurrentTextFile ,
25
24
exportedUris ,
@@ -231,7 +230,16 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
231
230
const content = await api . getDoc ( file . name , file . uri ) . then ( ( data ) => data . result . content ) ;
232
231
exportedUris . add ( file . uri . toString ( ) ) ; // Set optimistically
233
232
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
+ )
235
243
. then ( undefined , ( e ) => {
236
244
// Save failed, so remove this URI from the set
237
245
exportedUris . delete ( file . uri . toString ( ) ) ;
@@ -251,12 +259,15 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
251
259
) ;
252
260
}
253
261
254
- export async function compile ( docs : CurrentFile [ ] , flags ?: string ) : Promise < any > {
262
+ export async function compile ( docs : ( CurrentTextFile | CurrentBinaryFile ) [ ] , flags ?: string ) : Promise < any > {
255
263
const wsFolder = vscode . workspace . getWorkspaceFolder ( docs [ 0 ] . uri ) ;
256
264
const conf = vscode . workspace . getConfiguration ( "objectscript" , wsFolder || docs [ 0 ] . uri ) ;
257
265
flags = flags || conf . get ( "compileFlags" ) ;
258
266
const api = new AtelierAPI ( docs [ 0 ] . uri ) ;
259
267
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 ;
260
271
return vscode . window
261
272
. withProgress (
262
273
{
@@ -284,9 +295,11 @@ export async function compile(docs: CurrentFile[], flags?: string): Promise<any>
284
295
name : f . name ,
285
296
uri : u ,
286
297
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()
288
300
workspaceFolder : wsFolder . name ,
289
301
fileName : u . fsPath ,
302
+ content : "" ,
290
303
} ) ;
291
304
} ) ;
292
305
} ) ;
@@ -416,7 +429,7 @@ export async function namespaceCompile(askFlags = false): Promise<any> {
416
429
}
417
430
418
431
async function importFiles ( files : vscode . Uri [ ] , noCompile = false ) {
419
- const toCompile : CurrentFile [ ] = [ ] ;
432
+ const toCompile : ( CurrentTextFile | CurrentBinaryFile ) [ ] = [ ] ;
420
433
const rateLimiter = new RateLimiter ( 50 ) ;
421
434
await Promise . allSettled < void > (
422
435
files . map ( ( uri ) =>
0 commit comments