@@ -168,6 +168,8 @@ func TestService(t *testing.T) {
168
168
service , _ := projecttestutil .Setup (files , nil )
169
169
service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
170
170
assert .Check (t , service .GetScriptInfo ("/home/projects/TS/p1/y.ts" ) == nil )
171
+ // Avoid using initial file set after this point
172
+ files = nil //nolint:ineffassign
171
173
172
174
err := service .ChangeFile (
173
175
lsproto.VersionedTextDocumentIdentifier {
@@ -214,6 +216,8 @@ func TestService(t *testing.T) {
214
216
_ , project := service .EnsureDefaultProjectForFile ("/home/projects/TS/p1/src/index.ts" )
215
217
programBefore := project .GetProgram ()
216
218
assert .Equal (t , len (programBefore .GetSourceFiles ()), 2 )
219
+ // Avoid using initial file set after this point
220
+ files = nil //nolint:ineffassign
217
221
218
222
err := service .ChangeFile (
219
223
lsproto.VersionedTextDocumentIdentifier {
@@ -242,15 +246,16 @@ func TestService(t *testing.T) {
242
246
)
243
247
assert .NilError (t , err )
244
248
245
- files [ "/home/projects/TS/p1/tsconfig.json" ] = `{
249
+ err = host . FS (). WriteFile ( "/home/projects/TS/p1/tsconfig.json" , `{
246
250
"compilerOptions": {
247
251
"noLib": true,
248
252
"module": "nodenext",
249
253
"strict": true,
250
254
},
251
255
"include": ["./**/*"]
252
- }`
253
- host .ReplaceFS (files )
256
+ }` , false )
257
+ assert .NilError (t , err )
258
+
254
259
err = service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
255
260
{
256
261
Type : lsproto .FileChangeTypeChanged ,
@@ -270,23 +275,25 @@ func TestService(t *testing.T) {
270
275
t .Parallel ()
271
276
t .Run ("delete a file, close it, recreate it" , func (t * testing.T ) {
272
277
t .Parallel ()
273
- service , host := projecttestutil .Setup (defaultFiles , nil )
274
- service .OpenFile ("/home/projects/TS/p1/src/x.ts" , defaultFiles ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
275
- service .OpenFile ("/home/projects/TS/p1/src/index.ts" , defaultFiles ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
278
+ files := maps .Clone (defaultFiles )
279
+ service , host := projecttestutil .Setup (files , nil )
280
+ service .OpenFile ("/home/projects/TS/p1/src/x.ts" , files ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
281
+ service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
276
282
assert .Equal (t , service .SourceFileCount (), 2 )
283
+ // Avoid using initial file set after this point
284
+ files = nil //nolint:ineffassign
277
285
278
- files := maps .Clone (defaultFiles )
279
- delete (files , "/home/projects/TS/p1/src/x.ts" )
280
- host .ReplaceFS (files )
286
+ assert .NilError (t , host .FS ().Remove ("/home/projects/TS/p1/src/x.ts" ))
281
287
282
288
service .CloseFile ("/home/projects/TS/p1/src/x.ts" )
283
289
assert .Check (t , service .GetScriptInfo ("/home/projects/TS/p1/src/x.ts" ) == nil )
284
290
assert .Check (t , service .Projects ()[0 ].GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" ) == nil )
285
291
assert .Equal (t , service .SourceFileCount (), 1 )
286
292
287
- files ["/home/projects/TS/p1/src/x.ts" ] = ``
288
- host .ReplaceFS (files )
289
- service .OpenFile ("/home/projects/TS/p1/src/x.ts" , files ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
293
+ err := host .FS ().WriteFile ("/home/projects/TS/p1/src/x.ts" , "" , false )
294
+ assert .NilError (t , err )
295
+
296
+ service .OpenFile ("/home/projects/TS/p1/src/x.ts" , "" , core .ScriptKindTS , "" )
290
297
assert .Equal (t , service .GetScriptInfo ("/home/projects/TS/p1/src/x.ts" ).Text (), "" )
291
298
assert .Check (t , service .Projects ()[0 ].GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" ) != nil )
292
299
assert .Equal (t , service .Projects ()[0 ].GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" ).Text (), "" )
@@ -300,19 +307,22 @@ func TestService(t *testing.T) {
300
307
files := maps .Clone (defaultFiles )
301
308
delete (files , "/home/projects/TS/p1/tsconfig.json" )
302
309
service , host := projecttestutil .Setup (files , nil )
303
- service .OpenFile ("/home/projects/TS/p1/src/x.ts" , defaultFiles ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
304
- service .OpenFile ("/home/projects/TS/p1/src/index.ts" , defaultFiles ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
310
+ service .OpenFile ("/home/projects/TS/p1/src/x.ts" , files ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
311
+ service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
312
+ // Avoid using initial file set after this point
313
+ files = nil //nolint:ineffassign
305
314
306
- delete ( files , "/home/projects/TS/p1/src/x.ts" )
307
- host . ReplaceFS ( files )
315
+ err := host . FS (). Remove ( "/home/projects/TS/p1/src/x.ts" )
316
+ assert . NilError ( t , err )
308
317
309
318
service .CloseFile ("/home/projects/TS/p1/src/x.ts" )
310
319
assert .Check (t , service .GetScriptInfo ("/home/projects/TS/p1/src/x.ts" ) == nil )
311
320
assert .Check (t , service .Projects ()[0 ].GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" ) == nil )
312
321
313
- files ["/home/projects/TS/p1/src/x.ts" ] = ``
314
- host .ReplaceFS (files )
315
- service .OpenFile ("/home/projects/TS/p1/src/x.ts" , files ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
322
+ err = host .FS ().WriteFile ("/home/projects/TS/p1/src/x.ts" , "" , false )
323
+ assert .NilError (t , err )
324
+
325
+ service .OpenFile ("/home/projects/TS/p1/src/x.ts" , "" , core .ScriptKindTS , "" )
316
326
assert .Equal (t , service .GetScriptInfo ("/home/projects/TS/p1/src/x.ts" ).Text (), "" )
317
327
assert .Check (t , service .Projects ()[0 ].GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" ) != nil )
318
328
assert .Equal (t , service .Projects ()[0 ].GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" ).Text (), "" )
@@ -338,6 +348,8 @@ func TestService(t *testing.T) {
338
348
service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
339
349
service .OpenFile ("/home/projects/TS/p2/src/index.ts" , files ["/home/projects/TS/p2/src/index.ts" ].(string ), core .ScriptKindTS , "" )
340
350
assert .Equal (t , len (service .Projects ()), 2 )
351
+ // Avoid using initial file set after this point
352
+ files = nil //nolint:ineffassign
341
353
_ , p1 := service .EnsureDefaultProjectForFile ("/home/projects/TS/p1/src/index.ts" )
342
354
_ , p2 := service .EnsureDefaultProjectForFile ("/home/projects/TS/p2/src/index.ts" )
343
355
assert .Equal (
@@ -361,6 +373,8 @@ func TestService(t *testing.T) {
361
373
service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
362
374
service .OpenFile ("/home/projects/TS/p2/src/index.ts" , files ["/home/projects/TS/p2/src/index.ts" ].(string ), core .ScriptKindTS , "" )
363
375
assert .Equal (t , len (service .Projects ()), 2 )
376
+ // Avoid using initial file set after this point
377
+ files = nil //nolint:ineffassign
364
378
_ , p1 := service .EnsureDefaultProjectForFile ("/home/projects/TS/p1/src/index.ts" )
365
379
_ , p2 := service .EnsureDefaultProjectForFile ("/home/projects/TS/p2/src/index.ts" )
366
380
x1 := p1 .GetProgram ().GetSourceFile ("/home/projects/TS/p1/src/x.ts" )
@@ -375,15 +389,18 @@ func TestService(t *testing.T) {
375
389
376
390
t .Run ("change open file" , func (t * testing.T ) {
377
391
t .Parallel ()
378
- service , host := projecttestutil .Setup (defaultFiles , nil )
379
- service .OpenFile ("/home/projects/TS/p1/src/x.ts" , defaultFiles ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
380
- service .OpenFile ("/home/projects/TS/p1/src/index.ts" , defaultFiles ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
392
+ files := maps .Clone (defaultFiles )
393
+ service , host := projecttestutil .Setup (files , nil )
394
+ service .OpenFile ("/home/projects/TS/p1/src/x.ts" , files ["/home/projects/TS/p1/src/x.ts" ].(string ), core .ScriptKindTS , "" )
395
+ service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
381
396
_ , project := service .EnsureDefaultProjectForFile ("/home/projects/TS/p1/src/index.ts" )
382
397
programBefore := project .GetProgram ()
398
+ // Avoid using initial file set after this point
399
+ files = nil //nolint:ineffassign
400
+
401
+ err := host .FS ().WriteFile ("/home/projects/TS/p1/src/x.ts" , `export const x = 2;` , false )
402
+ assert .NilError (t , err )
383
403
384
- files := maps .Clone (defaultFiles )
385
- files ["/home/projects/TS/p1/src/x.ts" ] = `export const x = 2;`
386
- host .ReplaceFS (files )
387
404
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
388
405
{
389
406
Type : lsproto .FileChangeTypeChanged ,
@@ -396,14 +413,17 @@ func TestService(t *testing.T) {
396
413
397
414
t .Run ("change closed program file" , func (t * testing.T ) {
398
415
t .Parallel ()
399
- service , host := projecttestutil .Setup (defaultFiles , nil )
400
- service .OpenFile ("/home/projects/TS/p1/src/index.ts" , defaultFiles ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
416
+ files := maps .Clone (defaultFiles )
417
+ service , host := projecttestutil .Setup (files , nil )
418
+ service .OpenFile ("/home/projects/TS/p1/src/index.ts" , files ["/home/projects/TS/p1/src/index.ts" ].(string ), core .ScriptKindTS , "" )
401
419
_ , project := service .EnsureDefaultProjectForFile ("/home/projects/TS/p1/src/index.ts" )
402
420
programBefore := project .GetProgram ()
421
+ // Avoid using initial file set after this point
422
+ files = nil //nolint:ineffassign
423
+
424
+ err := host .FS ().WriteFile ("/home/projects/TS/p1/src/x.ts" , `export const x = 2;` , false )
425
+ assert .NilError (t , err )
403
426
404
- files := maps .Clone (defaultFiles )
405
- files ["/home/projects/TS/p1/src/x.ts" ] = `export const x = 2;`
406
- host .ReplaceFS (files )
407
427
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
408
428
{
409
429
Type : lsproto .FileChangeTypeChanged ,
@@ -435,14 +455,14 @@ func TestService(t *testing.T) {
435
455
program := project .GetProgram ()
436
456
assert .Equal (t , len (program .GetSemanticDiagnostics (projecttestutil .WithRequestID (t .Context ()), program .GetSourceFile ("/home/projects/TS/p1/src/index.ts" ))), 0 )
437
457
438
- filesCopy := maps .Clone (files )
439
- filesCopy ["/home/projects/TS/p1/tsconfig.json" ] = `{
458
+ err := host .FS ().WriteFile ("/home/projects/TS/p1/tsconfig.json" , `{
440
459
"compilerOptions": {
441
460
"noLib": false,
442
461
"strict": true
443
462
}
444
- }`
445
- host .ReplaceFS (filesCopy )
463
+ }` , false )
464
+ assert .NilError (t , err )
465
+
446
466
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
447
467
{
448
468
Type : lsproto .FileChangeTypeChanged ,
@@ -472,9 +492,9 @@ func TestService(t *testing.T) {
472
492
program := project .GetProgram ()
473
493
assert .Equal (t , len (program .GetSemanticDiagnostics (projecttestutil .WithRequestID (t .Context ()), program .GetSourceFile ("/home/projects/TS/p1/src/index.ts" ))), 0 )
474
494
475
- filesCopy := maps . Clone ( files )
476
- delete ( filesCopy , "/home/projects/TS/p1/src/x.ts" )
477
- host . ReplaceFS ( filesCopy )
495
+ err := host . FS (). Remove ( "/home/projects/TS/p1/src/x.ts" )
496
+ assert . NilError ( t , err )
497
+
478
498
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
479
499
{
480
500
Type : lsproto .FileChangeTypeDeleted ,
@@ -505,9 +525,9 @@ func TestService(t *testing.T) {
505
525
program := project .GetProgram ()
506
526
assert .Equal (t , len (program .GetSemanticDiagnostics (projecttestutil .WithRequestID (t .Context ()), program .GetSourceFile ("/home/projects/TS/p1/src/x.ts" ))), 0 )
507
527
508
- filesCopy := maps . Clone ( files )
509
- delete ( filesCopy , "/home/projects/TS/p1/src/index.ts" )
510
- host . ReplaceFS ( filesCopy )
528
+ err := host . FS (). Remove ( "/home/projects/TS/p1/src/index.ts" )
529
+ assert . NilError ( t , err )
530
+
511
531
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
512
532
{
513
533
Type : lsproto .FileChangeTypeDeleted ,
@@ -561,9 +581,9 @@ func TestService(t *testing.T) {
561
581
})
562
582
563
583
// Add the missing file
564
- filesCopy := maps . Clone ( files )
565
- filesCopy [ "/home/projects/TS/p1/src/y.ts" ] = `export const y = 1;`
566
- host . ReplaceFS ( filesCopy )
584
+ err := host . FS (). WriteFile ( "/home/projects/TS/p1/src/y.ts" , `export const y = 1;` , false )
585
+ assert . NilError ( t , err )
586
+
567
587
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
568
588
{
569
589
Type : lsproto .FileChangeTypeCreated ,
@@ -602,9 +622,9 @@ func TestService(t *testing.T) {
602
622
}))
603
623
604
624
// Add a new file through failed lookup watch
605
- filesCopy := maps . Clone ( files )
606
- filesCopy [ "/home/projects/TS/p1/src/z.ts" ] = `export const z = 1;`
607
- host . ReplaceFS ( filesCopy )
625
+ err := host . FS (). WriteFile ( "/home/projects/TS/p1/src/z.ts" , `export const z = 1;` , false )
626
+ assert . NilError ( t , err )
627
+
608
628
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
609
629
{
610
630
Type : lsproto .FileChangeTypeCreated ,
@@ -638,9 +658,10 @@ func TestService(t *testing.T) {
638
658
assert .Equal (t , len (program .GetSemanticDiagnostics (projecttestutil .WithRequestID (t .Context ()), program .GetSourceFile ("/home/projects/TS/p1/src/index.ts" ))), 1 )
639
659
640
660
// Add a new file through wildcard watch
641
- filesCopy := maps .Clone (files )
642
- filesCopy ["/home/projects/TS/p1/src/a.ts" ] = `const a = 1;`
643
- host .ReplaceFS (filesCopy )
661
+
662
+ err := host .FS ().WriteFile ("/home/projects/TS/p1/src/a.ts" , `const a = 1;` , false )
663
+ assert .NilError (t , err )
664
+
644
665
assert .NilError (t , service .OnWatchedFilesChanged (t .Context (), []* lsproto.FileEvent {
645
666
{
646
667
Type : lsproto .FileChangeTypeCreated ,
0 commit comments