@@ -2789,65 +2789,85 @@ namespace ts.projectSystem {
27892789 checkProjectRootFiles ( project , [ file1 . path ] ) ;
27902790 } ) ;
27912791
2792- it ( "when opening new file that doesnt exist on disk yet" , ( ) => {
2793- const host = createServerHost ( [ libFile ] ) ;
2794- let hasError = false ;
2795- const errLogger : server . Logger = {
2796- close : noop ,
2797- hasLevel : ( ) => true ,
2798- loggingEnabled : ( ) => true ,
2799- perftrc : noop ,
2800- info : noop ,
2801- msg : ( _s , type ) => {
2802- if ( type === server . Msg . Err ) {
2803- hasError = true ;
2804- }
2805- } ,
2806- startGroup : noop ,
2807- endGroup : noop ,
2808- getLogFileName : ( ) : string => undefined
2809- } ;
2810- const session = createSession ( host , { canUseEvents : true , logger : errLogger , useInferredProjectPerProjectRoot : true } ) ;
2792+ describe ( "when opening new file that doesnt exist on disk yet" , ( ) => {
2793+ function verifyNonExistentFile ( useProjectRoot : boolean ) {
2794+ const host = createServerHost ( [ libFile ] ) ;
2795+ let hasError = false ;
2796+ const errLogger : server . Logger = {
2797+ close : noop ,
2798+ hasLevel : ( ) => true ,
2799+ loggingEnabled : ( ) => true ,
2800+ perftrc : noop ,
2801+ info : noop ,
2802+ msg : ( _s , type ) => {
2803+ if ( type === server . Msg . Err ) {
2804+ hasError = true ;
2805+ }
2806+ } ,
2807+ startGroup : noop ,
2808+ endGroup : noop ,
2809+ getLogFileName : ( ) : string => undefined
2810+ } ;
2811+ const session = createSession ( host , { canUseEvents : true , logger : errLogger , useInferredProjectPerProjectRoot : true } ) ;
28112812
2812- const folderPath = "/user/someuser/projects/someFolder" ;
2813- const projectService = session . getProjectService ( ) ;
2814- const untitledFile = "untitled:Untitled-1" ;
2815- session . executeCommandSeq < protocol . OpenRequest > ( {
2816- command : server . CommandNames . Open ,
2817- arguments : {
2818- file : untitledFile ,
2819- fileContent : "" ,
2820- scriptKindName : "JS" ,
2821- projectRootPath : folderPath
2813+ const folderPath = "/user/someuser/projects/someFolder" ;
2814+ const projectService = session . getProjectService ( ) ;
2815+ const untitledFile = "untitled:Untitled-1" ;
2816+ session . executeCommandSeq < protocol . OpenRequest > ( {
2817+ command : server . CommandNames . Open ,
2818+ arguments : {
2819+ file : untitledFile ,
2820+ fileContent : "" ,
2821+ scriptKindName : "JS" ,
2822+ projectRootPath : useProjectRoot ? folderPath : undefined
2823+ }
2824+ } ) ;
2825+ checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
2826+ const infoForUntitledAtProjectRoot = projectService . getScriptInfoForPath ( `${ folderPath . toLowerCase ( ) } /${ untitledFile . toLowerCase ( ) } ` as Path ) ;
2827+ const infoForUnitiledAtRoot = projectService . getScriptInfoForPath ( `/${ untitledFile . toLowerCase ( ) } ` as Path ) ;
2828+ if ( useProjectRoot ) {
2829+ assert . isDefined ( infoForUntitledAtProjectRoot ) ;
2830+ assert . isUndefined ( infoForUnitiledAtRoot ) ;
28222831 }
2823- } ) ;
2824- checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
2825- host . checkTimeoutQueueLength ( 2 ) ;
2826-
2827- const newTimeoutId = host . getNextTimeoutId ( ) ;
2828- const expectedSequenceId = session . getNextSeq ( ) ;
2829- session . executeCommandSeq < protocol . GeterrRequest > ( {
2830- command : server . CommandNames . Geterr ,
2831- arguments : {
2832- delay : 0 ,
2833- files : [ untitledFile ]
2832+ else {
2833+ assert . isDefined ( infoForUnitiledAtRoot ) ;
2834+ assert . isUndefined ( infoForUntitledAtProjectRoot ) ;
28342835 }
2835- } ) ;
2836- host . checkTimeoutQueueLength ( 3 ) ;
2836+ host . checkTimeoutQueueLength ( 2 ) ;
28372837
2838- // Run the last one = get error request
2839- host . runQueuedTimeoutCallbacks ( newTimeoutId ) ;
2838+ const newTimeoutId = host . getNextTimeoutId ( ) ;
2839+ const expectedSequenceId = session . getNextSeq ( ) ;
2840+ session . executeCommandSeq < protocol . GeterrRequest > ( {
2841+ command : server . CommandNames . Geterr ,
2842+ arguments : {
2843+ delay : 0 ,
2844+ files : [ untitledFile ]
2845+ }
2846+ } ) ;
2847+ host . checkTimeoutQueueLength ( 3 ) ;
28402848
2841- assert . isFalse ( hasError ) ;
2842- host . checkTimeoutQueueLength ( 2 ) ;
2843- checkErrorMessage ( host , "syntaxDiag" , { file : untitledFile , diagnostics : [ ] } ) ;
2844- host . clearOutput ( ) ;
2849+ // Run the last one = get error request
2850+ host . runQueuedTimeoutCallbacks ( newTimeoutId ) ;
28452851
2846- host . runQueuedImmediateCallbacks ( ) ;
2847- assert . isFalse ( hasError ) ;
2848- checkErrorMessage ( host , "semanticDiag" , { file : untitledFile , diagnostics : [ ] } ) ;
2852+ assert . isFalse ( hasError ) ;
2853+ host . checkTimeoutQueueLength ( 2 ) ;
2854+ checkErrorMessage ( host , "syntaxDiag" , { file : untitledFile , diagnostics : [ ] } ) ;
2855+ host . clearOutput ( ) ;
28492856
2850- checkCompleteEvent ( host , 2 , expectedSequenceId ) ;
2857+ host . runQueuedImmediateCallbacks ( ) ;
2858+ assert . isFalse ( hasError ) ;
2859+ checkErrorMessage ( host , "semanticDiag" , { file : untitledFile , diagnostics : [ ] } ) ;
2860+
2861+ checkCompleteEvent ( host , 2 , expectedSequenceId ) ;
2862+ }
2863+
2864+ it ( "has projectRoot" , ( ) => {
2865+ verifyNonExistentFile ( /*useProjectRoot*/ true ) ;
2866+ } ) ;
2867+
2868+ it ( "does not have projectRoot" , ( ) => {
2869+ verifyNonExistentFile ( /*useProjectRoot*/ false ) ;
2870+ } ) ;
28512871 } ) ;
28522872 } ) ;
28532873
0 commit comments