@@ -3479,6 +3479,102 @@ namespace ts.projectSystem {
3479
3479
openFilesForSession ( [ { file, projectRootPath } ] , session ) ;
3480
3480
}
3481
3481
} ) ;
3482
+
3483
+ describe ( "CompileOnSaveAffectedFileListRequest with and without projectFileName in request" , ( ) => {
3484
+ const projectRoot = "/user/username/projects/myproject" ;
3485
+ const core : File = {
3486
+ path : `${ projectRoot } /core/core.ts` ,
3487
+ content : "let z = 10;"
3488
+ } ;
3489
+ const app1 : File = {
3490
+ path : `${ projectRoot } /app1/app.ts` ,
3491
+ content : "let x = 10;"
3492
+ } ;
3493
+ const app2 : File = {
3494
+ path : `${ projectRoot } /app2/app.ts` ,
3495
+ content : "let y = 10;"
3496
+ } ;
3497
+ const app1Config : File = {
3498
+ path : `${ projectRoot } /app1/tsconfig.json` ,
3499
+ content : JSON . stringify ( {
3500
+ files : [ "app.ts" , "../core/core.ts" ] ,
3501
+ compilerOptions : { outFile : "build/output.js" } ,
3502
+ compileOnSave : true
3503
+ } )
3504
+ } ;
3505
+ const app2Config : File = {
3506
+ path : `${ projectRoot } /app2/tsconfig.json` ,
3507
+ content : JSON . stringify ( {
3508
+ files : [ "app.ts" , "../core/core.ts" ] ,
3509
+ compilerOptions : { outFile : "build/output.js" } ,
3510
+ compileOnSave : true
3511
+ } )
3512
+ } ;
3513
+ const files = [ libFile , core , app1 , app2 , app1Config , app2Config ] ;
3514
+
3515
+ function insertString ( session : TestSession , file : File ) {
3516
+ session . executeCommandSeq < protocol . ChangeRequest > ( {
3517
+ command : protocol . CommandTypes . Change ,
3518
+ arguments : {
3519
+ file : file . path ,
3520
+ line : 1 ,
3521
+ offset : 1 ,
3522
+ endLine : 1 ,
3523
+ endOffset : 1 ,
3524
+ insertString : "let k = 1"
3525
+ }
3526
+ } ) ;
3527
+ }
3528
+
3529
+ function getSession ( ) {
3530
+ const host = createServerHost ( files ) ;
3531
+ const session = createSession ( host ) ;
3532
+ openFilesForSession ( [ app1 , app2 , core ] , session ) ;
3533
+ const service = session . getProjectService ( ) ;
3534
+ checkNumberOfProjects ( session . getProjectService ( ) , { configuredProjects : 2 } ) ;
3535
+ const project1 = service . configuredProjects . get ( app1Config . path ) ! ;
3536
+ const project2 = service . configuredProjects . get ( app2Config . path ) ! ;
3537
+ checkProjectActualFiles ( project1 , [ libFile . path , app1 . path , core . path , app1Config . path ] ) ;
3538
+ checkProjectActualFiles ( project2 , [ libFile . path , app2 . path , core . path , app2Config . path ] ) ;
3539
+ insertString ( session , app1 ) ;
3540
+ insertString ( session , app2 ) ;
3541
+ assert . equal ( project1 . dirty , true ) ;
3542
+ assert . equal ( project2 . dirty , true ) ;
3543
+ return session ;
3544
+ }
3545
+
3546
+ it ( "when projectFile is specified" , ( ) => {
3547
+ const session = getSession ( ) ;
3548
+ const response = session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
3549
+ command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
3550
+ arguments : {
3551
+ file : core . path ,
3552
+ projectFileName : app1Config . path
3553
+ }
3554
+ } ) . response ;
3555
+ assert . deepEqual ( response , [
3556
+ { projectFileName : app1Config . path , fileNames : [ core . path , app1 . path ] , projectUsesOutFile : true }
3557
+ ] ) ;
3558
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app1Config . path ) ! . dirty , false ) ;
3559
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app2Config . path ) ! . dirty , true ) ;
3560
+ } ) ;
3561
+
3562
+ it ( "when projectFile is not specified" , ( ) => {
3563
+ const session = getSession ( ) ;
3564
+ const response = session . executeCommandSeq < protocol . CompileOnSaveAffectedFileListRequest > ( {
3565
+ command : protocol . CommandTypes . CompileOnSaveAffectedFileList ,
3566
+ arguments : {
3567
+ file : core . path
3568
+ }
3569
+ } ) . response ;
3570
+ assert . deepEqual ( response , [
3571
+ { projectFileName : app1Config . path , fileNames : [ core . path , app1 . path ] , projectUsesOutFile : true } ,
3572
+ { projectFileName : app2Config . path , fileNames : [ core . path , app2 . path ] , projectUsesOutFile : true }
3573
+ ] ) ;
3574
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app1Config . path ) ! . dirty , false ) ;
3575
+ assert . equal ( session . getProjectService ( ) . configuredProjects . get ( app2Config . path ) ! . dirty , false ) ;
3576
+ } ) ;
3577
+ } ) ;
3482
3578
} ) ;
3483
3579
3484
3580
describe ( "tsserverProjectSystem Proper errors" , ( ) => {
0 commit comments