@@ -113,6 +113,13 @@ namespace ts.projectSystem {
113113 fileOrFolderList ) ;
114114 }
115115
116+ export function createSession ( host : server . ServerHost , typingsInstaller ?: server . ITypingsInstaller ) {
117+ if ( typingsInstaller === undefined ) {
118+ typingsInstaller = new TestTypingsInstaller ( "/a/data/" , host ) ;
119+ }
120+ return new server . Session ( host , nullCancellationToken , /*useSingleInferredProject*/ false , typingsInstaller , Utils . byteLength , process . hrtime , nullLogger , /*canUseEvents*/ false ) ;
121+ }
122+
116123 export interface CreateProjectServiceParameters {
117124 cancellationToken ?: HostCancellationToken ;
118125 logger ?: server . Logger ;
@@ -1699,7 +1706,36 @@ namespace ts.projectSystem {
16991706 "File '/a/cache/node_modules/@types/lib/index.tsx' does not exist." ,
17001707 "File '/a/cache/node_modules/@types/lib/index.d.ts' exist - use it as a name resolution result." ,
17011708 ] ) ;
1702- checkProjectActualFiles ( proj , [ file1 . path , lib . path ] ) ;
1709+ checkProjectActualFiles ( proj , [ file1 . path , lib . path ] ) ;
1710+ } ) ;
1711+ } ) ;
1712+
1713+ describe ( "navigate-to for javascript project" , ( ) => {
1714+ function containsNavToItem ( items : server . protocol . NavtoItem [ ] , itemName : string , itemKind : string ) {
1715+ return find ( items , item => item . name === itemName && item . kind === itemKind ) !== undefined ;
1716+ }
1717+
1718+ it ( "should not include type symbols" , ( ) => {
1719+ const file1 : FileOrFolder = {
1720+ path : "/a/b/file1.js" ,
1721+ content : "function foo() {}"
1722+ } ;
1723+ const configFile : FileOrFolder = {
1724+ path : "/a/b/jsconfig.json" ,
1725+ content : "{}"
1726+ } ;
1727+ const host = createServerHost ( [ file1 , configFile , libFile ] ) ;
1728+ const session = createSession ( host ) ;
1729+ openFilesForSession ( [ file1 ] , session ) ;
1730+
1731+ // Try to find some interface type defined in lib.d.ts
1732+ const libTypeNavToRequest = makeSessionRequest < server . protocol . NavtoRequestArgs > ( server . CommandNames . Navto , { searchValue : "Document" , file : file1 . path , projectFileName : configFile . path } ) ;
1733+ const items : server . protocol . NavtoItem [ ] = session . executeCommand ( libTypeNavToRequest ) . response ;
1734+ assert . isFalse ( containsNavToItem ( items , "Document" , "interface" ) , `Found lib.d.ts symbol in JavaScript project nav to request result.` ) ;
1735+
1736+ const localFunctionNavToRequst = makeSessionRequest < server . protocol . NavtoRequestArgs > ( server . CommandNames . Navto , { searchValue : "foo" , file : file1 . path , projectFileName : configFile . path } ) ;
1737+ const items2 : server . protocol . NavtoItem [ ] = session . executeCommand ( localFunctionNavToRequst ) . response ;
1738+ assert . isTrue ( containsNavToItem ( items2 , "foo" , "function" ) , `Cannot find function symbol "foo".` ) ;
17031739 } ) ;
17041740 } ) ;
17051741}
0 commit comments