@@ -2111,9 +2111,6 @@ namespace ts.projectSystem {
21112111 /*closedFiles*/ undefined ) ;
21122112
21132113 checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
2114- const changedFiles = projectService . getChangedFiles_TestOnly ( ) ;
2115- assert ( changedFiles && changedFiles . length === 1 , `expected 1 changed file, got ${ JSON . stringify ( changedFiles && changedFiles . length || 0 ) } ` ) ;
2116-
21172114 projectService . ensureInferredProjectsUpToDate_TestOnly ( ) ;
21182115 checkNumberOfProjects ( projectService , { inferredProjects : 2 } ) ;
21192116 } ) ;
@@ -2904,6 +2901,83 @@ namespace ts.projectSystem {
29042901 tags : [ ]
29052902 } ) ;
29062903 } ) ;
2904+
2905+ it ( "files opened, closed affecting multiple projects" , ( ) => {
2906+ const file : FileOrFolder = {
2907+ path : "/a/b/projects/config/file.ts" ,
2908+ content : `import {a} from "../files/file1"; export let b = a;`
2909+ } ;
2910+ const config : FileOrFolder = {
2911+ path : "/a/b/projects/config/tsconfig.json" ,
2912+ content : ""
2913+ } ;
2914+ const filesFile1 : FileOrFolder = {
2915+ path : "/a/b/projects/files/file1.ts" ,
2916+ content : "export let a = 10;"
2917+ } ;
2918+ const filesFile2 : FileOrFolder = {
2919+ path : "/a/b/projects/files/file2.ts" ,
2920+ content : "export let aa = 10;"
2921+ } ;
2922+
2923+ const files = [ config , file , filesFile1 , filesFile2 , libFile ] ;
2924+ const host = createServerHost ( files ) ;
2925+ const session = createSession ( host ) ;
2926+ // Create configured project
2927+ session . executeCommandSeq < protocol . OpenRequest > ( {
2928+ command : protocol . CommandTypes . Open ,
2929+ arguments : {
2930+ file : file . path
2931+ }
2932+ } ) ;
2933+
2934+ const projectService = session . getProjectService ( ) ;
2935+ const configuredProject = projectService . configuredProjects . get ( config . path ) ;
2936+ verifyConfiguredProject ( ) ;
2937+
2938+ // open files/file1 = should not create another project
2939+ session . executeCommandSeq < protocol . OpenRequest > ( {
2940+ command : protocol . CommandTypes . Open ,
2941+ arguments : {
2942+ file : filesFile1 . path
2943+ }
2944+ } ) ;
2945+ verifyConfiguredProject ( ) ;
2946+
2947+ // Close the file = should still have project
2948+ session . executeCommandSeq < protocol . CloseRequest > ( {
2949+ command : protocol . CommandTypes . Close ,
2950+ arguments : {
2951+ file : file . path
2952+ }
2953+ } ) ;
2954+ verifyConfiguredProject ( ) ;
2955+
2956+ // Open files/file2 - should create inferred project and close configured project
2957+ session . executeCommandSeq < protocol . OpenRequest > ( {
2958+ command : protocol . CommandTypes . Open ,
2959+ arguments : {
2960+ file : filesFile2 . path
2961+ }
2962+ } ) ;
2963+ checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
2964+ checkProjectActualFiles ( projectService . inferredProjects [ 0 ] , [ libFile . path , filesFile2 . path ] ) ;
2965+
2966+ // Actions on file1 would result in assert
2967+ session . executeCommandSeq < protocol . OccurrencesRequest > ( {
2968+ command : protocol . CommandTypes . Occurrences ,
2969+ arguments : {
2970+ file : filesFile1 . path ,
2971+ line : 1 ,
2972+ offset : filesFile1 . content . indexOf ( "a" )
2973+ }
2974+ } ) ;
2975+
2976+ function verifyConfiguredProject ( ) {
2977+ checkNumberOfProjects ( projectService , { configuredProjects : 1 } ) ;
2978+ checkProjectActualFiles ( configuredProject , [ file . path , filesFile1 . path , libFile . path , config . path ] ) ;
2979+ }
2980+ } ) ;
29072981 } ) ;
29082982
29092983 describe ( "tsserverProjectSystem Proper errors" , ( ) => {
0 commit comments