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