11namespace ts . projectSystem {
2+ export function verifyDynamic ( service : server . ProjectService , path : string ) {
3+ const info = Debug . assertDefined ( service . filenameToScriptInfo . get ( path ) , `Expected ${ path } in :: ${ JSON . stringify ( arrayFrom ( service . filenameToScriptInfo . entries ( ) , ( [ key , f ] ) => ( { key, fileName : f . fileName , path : f . path } ) ) ) } ` ) ;
4+ assert . isTrue ( info . isDynamic ) ;
5+ }
6+
27 describe ( "unittests:: tsserver:: Untitled files" , ( ) => {
8+ const untitledFile = "untitled:^Untitled-1" ;
39 it ( "Can convert positions to locations" , ( ) => {
410 const aTs : File = { path : "/proj/a.ts" , content : "" } ;
511 const tsconfig : File = { path : "/proj/tsconfig.json" , content : "{}" } ;
6- const session = createSession ( createServerHost ( [ aTs , tsconfig ] ) ) ;
12+ const session = createSession ( createServerHost ( [ aTs , tsconfig ] ) , { useInferredProjectPerProjectRoot : true } ) ;
713
814 openFilesForSession ( [ aTs ] , session ) ;
915
10- const untitledFile = "untitled:^Untitled-1" ;
1116 executeSessionRequestNoResponse < protocol . OpenRequest > ( session , protocol . CommandTypes . Open , {
1217 file : untitledFile ,
1318 fileContent : `/// <reference path="../../../../../../typings/@epic/Core.d.ts" />\nlet foo = 1;\nfooo/**/` ,
1419 scriptKindName : "TS" ,
1520 projectRootPath : "/proj" ,
1621 } ) ;
17-
22+ verifyDynamic ( session . getProjectService ( ) , `/proj/untitled:^untitled-1` ) ;
1823 const response = executeSessionRequest < protocol . CodeFixRequest , protocol . CodeFixResponse > ( session , protocol . CommandTypes . GetCodeFixes , {
1924 file : untitledFile ,
2025 startLine : 3 ,
@@ -41,5 +46,38 @@ namespace ts.projectSystem {
4146 } ,
4247 ] ) ;
4348 } ) ;
49+
50+ it ( "opening untitled files" , ( ) => {
51+ const config : File = {
52+ path : `${ tscWatch . projectRoot } /tsconfig.json` ,
53+ content : "{}"
54+ } ;
55+ const host = createServerHost ( [ config , libFile ] , { useCaseSensitiveFileNames : true , currentDirectory : tscWatch . projectRoot } ) ;
56+ const service = createProjectService ( host ) ;
57+ service . openClientFile ( untitledFile , "const x = 10;" , /*scriptKind*/ undefined , tscWatch . projectRoot ) ;
58+ checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
59+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ untitledFile , libFile . path ] ) ;
60+ verifyDynamic ( service , `${ tscWatch . projectRoot } /${ untitledFile } ` ) ;
61+
62+ const untitled : File = {
63+ path : `${ tscWatch . projectRoot } /Untitled-1.ts` ,
64+ content : "const x = 10;"
65+ } ;
66+ host . writeFile ( untitled . path , untitled . content ) ;
67+ host . checkTimeoutQueueLength ( 0 ) ;
68+ service . openClientFile ( untitled . path , untitled . content , /*scriptKind*/ undefined , tscWatch . projectRoot ) ;
69+ checkNumberOfProjects ( service , { configuredProjects : 1 , inferredProjects : 1 } ) ;
70+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ untitled . path , libFile . path , config . path ] ) ;
71+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ untitledFile , libFile . path ] ) ;
72+
73+ service . closeClientFile ( untitledFile ) ;
74+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ untitled . path , libFile . path , config . path ] ) ;
75+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ untitledFile , libFile . path ] ) ;
76+
77+ service . openClientFile ( untitledFile , "const x = 10;" , /*scriptKind*/ undefined , tscWatch . projectRoot ) ;
78+ verifyDynamic ( service , `${ tscWatch . projectRoot } /${ untitledFile } ` ) ;
79+ checkProjectActualFiles ( service . configuredProjects . get ( config . path ) ! , [ untitled . path , libFile . path , config . path ] ) ;
80+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ untitledFile , libFile . path ] ) ;
81+ } ) ;
4482 } ) ;
4583}
0 commit comments