@@ -760,5 +760,63 @@ namespace ts.projectSystem {
760760 assert . equal ( project2 . pendingReload , ConfigFileProgramReloadLevel . None ) ; // External project referenced configured project loaded
761761 checkProjectActualFiles ( project2 , [ config . path , f1 . path ] ) ;
762762 } ) ;
763+
764+ it ( "handles creation of external project with jsconfig before jsconfig creation watcher is invoked" , ( ) => {
765+ const projectLocation = `/user/username/projects/WebApplication36/WebApplication36` ;
766+ const projectFileName = `${ projectLocation } /WebApplication36.csproj` ;
767+ const tsconfig : File = {
768+ path : `${ projectLocation } /tsconfig.json` ,
769+ content : "{}"
770+ } ;
771+ const files = [ libFile , tsconfig ] ;
772+ const host = createServerHost ( files ) ;
773+ const service = createProjectService ( host ) ;
774+
775+ // Create external project
776+ service . openExternalProjects ( [ {
777+ projectFileName,
778+ rootFiles : [ { fileName : tsconfig . path } ] ,
779+ options : { allowJs : false }
780+ } ] ) ;
781+ checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
782+ const configProject = service . configuredProjects . get ( tsconfig . path . toLowerCase ( ) ) ! ;
783+ checkProjectActualFiles ( configProject , [ tsconfig . path ] ) ;
784+
785+ // write js file, open external project and open it for edit
786+ const jsFilePath = `${ projectLocation } /javascript.js` ;
787+ host . writeFile ( jsFilePath , "" ) ;
788+ service . openExternalProjects ( [ {
789+ projectFileName,
790+ rootFiles : [ { fileName : tsconfig . path } , { fileName : jsFilePath } ] ,
791+ options : { allowJs : false }
792+ } ] ) ;
793+ service . applyChangesInOpenFiles ( [
794+ { fileName : jsFilePath , scriptKind : ScriptKind . JS , content : "" }
795+ ] , /*changedFiles*/ undefined , /*closedFiles*/ undefined ) ;
796+ checkNumberOfProjects ( service , { configuredProjects : 1 , inferredProjects : 1 } ) ;
797+ checkProjectActualFiles ( configProject , [ tsconfig . path ] ) ;
798+ const inferredProject = service . inferredProjects [ 0 ] ;
799+ checkProjectActualFiles ( inferredProject , [ libFile . path , jsFilePath ] ) ;
800+
801+ // write jsconfig file
802+ const jsConfig : File = {
803+ path : `${ projectLocation } /jsconfig.json` ,
804+ content : "{}"
805+ } ;
806+ // Dont invoke file creation watchers as the repro suggests
807+ host . ensureFileOrFolder ( jsConfig , /*ignoreWatchInvokedWithTriggerAsFileCreate*/ true ) ;
808+
809+ // Open external project
810+ service . openExternalProjects ( [ {
811+ projectFileName,
812+ rootFiles : [ { fileName : jsConfig . path } , { fileName : tsconfig . path } , { fileName : jsFilePath } ] ,
813+ options : { allowJs : false }
814+ } ] ) ;
815+ checkNumberOfProjects ( service , { configuredProjects : 2 , inferredProjects : 1 } ) ;
816+ checkProjectActualFiles ( configProject , [ tsconfig . path ] ) ;
817+ assert . isTrue ( inferredProject . isOrphan ( ) ) ;
818+ const jsConfigProject = service . configuredProjects . get ( jsConfig . path . toLowerCase ( ) ) ! ;
819+ checkProjectActualFiles ( jsConfigProject , [ jsConfig . path , jsFilePath , libFile . path ] ) ;
820+ } ) ;
763821 } ) ;
764822}
0 commit comments