@@ -3,35 +3,66 @@ namespace ts.projectSystem {
33 function setup ( ) {
44 const file1 : File = {
55 path : `${ tscWatch . projectRoot } /a.ts` ,
6- content : `import { y } from "./b";
6+ content : `import { y, cc } from "./b";
7+ import { something } from "something";
78class c { prop = "hello"; foo() { return this.prop; } }`
89 } ;
910 const file2 : File = {
1011 path : `${ tscWatch . projectRoot } /b.ts` ,
11- content : "export const y = 10;"
12+ content : `export { cc } from "./c";
13+ import { something } from "something";
14+ export const y = 10;`
15+ } ;
16+ const file3 : File = {
17+ path : `${ tscWatch . projectRoot } /c.ts` ,
18+ content : `export const cc = 10;`
19+ } ;
20+ const something : File = {
21+ path : `${ tscWatch . projectRoot } /node_modules/something/index.d.ts` ,
22+ content : "export const something = 10;"
1223 } ;
1324 const configFile : File = {
1425 path : `${ tscWatch . projectRoot } /tsconfig.json` ,
1526 content : "{}"
1627 } ;
17- const host = createServerHost ( [ file1 , file2 , libFile , configFile ] ) ;
28+ const host = createServerHost ( [ file1 , file2 , file3 , something , libFile , configFile ] ) ;
1829 const session = createSession ( host , { syntaxOnly : true , useSingleInferredProject : true } ) ;
19- return { host, session, file1, file2, configFile } ;
30+ return { host, session, file1, file2, file3 , something , configFile } ;
2031 }
2132
2233 it ( "open files are added to inferred project even if config file is present and semantic operations succeed" , ( ) => {
23- const { host, session, file1, file2 } = setup ( ) ;
34+ const { host, session, file1, file2, file3 , something } = setup ( ) ;
2435 const service = session . getProjectService ( ) ;
2536 openFilesForSession ( [ file1 ] , session ) ;
2637 checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
2738 const project = service . inferredProjects [ 0 ] ;
28- checkProjectActualFiles ( project , [ libFile . path , file1 . path ] ) ; // Import is not resolved
39+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path ] ) ; // Relative import from open file is resolves but not non relative
2940 verifyCompletions ( ) ;
41+ verifyGoToDefToB ( ) ;
3042
3143 openFilesForSession ( [ file2 ] , session ) ;
3244 checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
33- checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path ] ) ;
45+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , file3 . path ] ) ;
3446 verifyCompletions ( ) ;
47+ verifyGoToDefToB ( ) ;
48+ verifyGoToDefToC ( ) ;
49+
50+ openFilesForSession ( [ file3 ] , session ) ;
51+ checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
52+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , file3 . path ] ) ;
53+
54+ openFilesForSession ( [ something ] , session ) ;
55+ checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
56+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , file3 . path , something . path ] ) ;
57+
58+ // Close open files and verify resolutions
59+ closeFilesForSession ( [ file3 ] , session ) ;
60+ checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
61+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , file3 . path , something . path ] ) ;
62+
63+ closeFilesForSession ( [ file2 ] , session ) ;
64+ checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
65+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , file3 . path , something . path ] ) ;
3566
3667 function verifyCompletions ( ) {
3768 assert . isTrue ( project . languageServiceEnabled ) ;
@@ -62,6 +93,34 @@ class c { prop = "hello"; foo() { return this.prop; } }`
6293 source : undefined
6394 } ;
6495 }
96+
97+ function verifyGoToDefToB ( ) {
98+ const response = session . executeCommandSeq < protocol . DefinitionAndBoundSpanRequest > ( {
99+ command : protocol . CommandTypes . DefinitionAndBoundSpan ,
100+ arguments : protocolFileLocationFromSubstring ( file1 , "y" )
101+ } ) . response as protocol . DefinitionInfoAndBoundSpan ;
102+ assert . deepEqual ( response , {
103+ definitions : [ {
104+ file : file2 . path ,
105+ ...protocolTextSpanWithContextFromSubstring ( { fileText : file2 . content , text : "y" , contextText : "export const y = 10;" } )
106+ } ] ,
107+ textSpan : protocolTextSpanWithContextFromSubstring ( { fileText : file1 . content , text : "y" } )
108+ } ) ;
109+ }
110+
111+ function verifyGoToDefToC ( ) {
112+ const response = session . executeCommandSeq < protocol . DefinitionAndBoundSpanRequest > ( {
113+ command : protocol . CommandTypes . DefinitionAndBoundSpan ,
114+ arguments : protocolFileLocationFromSubstring ( file1 , "cc" )
115+ } ) . response as protocol . DefinitionInfoAndBoundSpan ;
116+ assert . deepEqual ( response , {
117+ definitions : [ {
118+ file : file3 . path ,
119+ ...protocolTextSpanWithContextFromSubstring ( { fileText : file3 . content , text : "cc" , contextText : "export const cc = 10;" } )
120+ } ] ,
121+ textSpan : protocolTextSpanWithContextFromSubstring ( { fileText : file1 . content , text : "cc" } )
122+ } ) ;
123+ }
65124 } ) ;
66125
67126 it ( "throws on unsupported commands" , ( ) => {
@@ -97,7 +156,7 @@ class c { prop = "hello"; foo() { return this.prop; } }`
97156 } ) ;
98157
99158 it ( "should not include auto type reference directives" , ( ) => {
100- const { host, session, file1 } = setup ( ) ;
159+ const { host, session, file1, file2 } = setup ( ) ;
101160 const atTypes : File = {
102161 path : `/node_modules/@types/somemodule/index.d.ts` ,
103162 content : "export const something = 10;"
@@ -107,7 +166,7 @@ class c { prop = "hello"; foo() { return this.prop; } }`
107166 openFilesForSession ( [ file1 ] , session ) ;
108167 checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
109168 const project = service . inferredProjects [ 0 ] ;
110- checkProjectActualFiles ( project , [ libFile . path , file1 . path ] ) ; // Should not contain atTypes
169+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path ] ) ; // Should not contain atTypes
111170 } ) ;
112171 } ) ;
113172}
0 commit comments