1
1
namespace 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
+
2
7
describe ( "unittests:: tsserver:: Untitled files" , ( ) => {
8
+ const untitledFile = "untitled:^Untitled-1" ;
3
9
it ( "Can convert positions to locations" , ( ) => {
4
10
const aTs : File = { path : "/proj/a.ts" , content : "" } ;
5
11
const tsconfig : File = { path : "/proj/tsconfig.json" , content : "{}" } ;
6
- const session = createSession ( createServerHost ( [ aTs , tsconfig ] ) ) ;
12
+ const session = createSession ( createServerHost ( [ aTs , tsconfig ] ) , { useInferredProjectPerProjectRoot : true } ) ;
7
13
8
14
openFilesForSession ( [ aTs ] , session ) ;
9
15
10
- const untitledFile = "untitled:^Untitled-1" ;
11
16
executeSessionRequestNoResponse < protocol . OpenRequest > ( session , protocol . CommandTypes . Open , {
12
17
file : untitledFile ,
13
18
fileContent : `/// <reference path="../../../../../../typings/@epic/Core.d.ts" />\nlet foo = 1;\nfooo/**/` ,
14
19
scriptKindName : "TS" ,
15
20
projectRootPath : "/proj" ,
16
21
} ) ;
17
-
22
+ verifyDynamic ( session . getProjectService ( ) , `/proj/untitled:^untitled-1` ) ;
18
23
const response = executeSessionRequest < protocol . CodeFixRequest , protocol . CodeFixResponse > ( session , protocol . CommandTypes . GetCodeFixes , {
19
24
file : untitledFile ,
20
25
startLine : 3 ,
@@ -41,5 +46,38 @@ namespace ts.projectSystem {
41
46
} ,
42
47
] ) ;
43
48
} ) ;
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
+ } ) ;
44
82
} ) ;
45
83
}
0 commit comments