@@ -12,7 +12,6 @@ import { traceObservable, tracePromise, traceSync } from './tracing';
1212import {
1313 isConfigFile ,
1414 isDeclarationFile ,
15- isDependencyFile ,
1615 isGlobalTSFile ,
1716 isJSTSFile ,
1817 isPackageJsonFile ,
@@ -597,12 +596,6 @@ export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
597596 */
598597 private fs : InMemoryFileSystem ;
599598
600- /**
601- * List of files that project consist of (based on tsconfig includes/excludes and wildcards).
602- * Each item is a relative file path
603- */
604- expectedFilePaths : string [ ] ;
605-
606599 /**
607600 * Current list of files that were implicitly added to project
608601 * (every time when we need to extract data from a file that we haven't touched yet).
@@ -621,11 +614,10 @@ export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
621614 */
622615 private versions : Map < string , number > ;
623616
624- constructor ( rootPath : string , options : ts . CompilerOptions , fs : InMemoryFileSystem , expectedFiles : string [ ] , versions : Map < string , number > , private logger : Logger = new NoopLogger ( ) ) {
617+ constructor ( rootPath : string , options : ts . CompilerOptions , fs : InMemoryFileSystem , versions : Map < string , number > , private logger : Logger = new NoopLogger ( ) ) {
625618 this . rootPath = rootPath ;
626619 this . options = options ;
627620 this . fs = fs ;
628- this . expectedFilePaths = expectedFiles ;
629621 this . versions = versions ;
630622 this . projectVersion = 1 ;
631623 this . filePaths = [ ] ;
@@ -770,6 +762,12 @@ export class ProjectConfiguration {
770762 */
771763 private rootFilePath : string ;
772764
765+ /**
766+ * List of files that project consist of (based on tsconfig includes/excludes and wildcards).
767+ * Each item is a relative file path
768+ */
769+ private expectedFilePaths = new Set < string > ( ) ;
770+
773771 /**
774772 * @param fs file system to use
775773 * @param documentRegistry Shared DocumentRegistry that manages SourceFile objects
@@ -815,6 +813,7 @@ export class ProjectConfiguration {
815813 this . ensuredAllFiles = false ;
816814 this . service = undefined ;
817815 this . host = undefined ;
816+ this . expectedFilePaths = new Set ( ) ;
818817 }
819818
820819 /**
@@ -877,7 +876,7 @@ export class ProjectConfiguration {
877876 }
878877 const base = dir || this . fs . path ;
879878 const configParseResult = ts . parseJsonConfigFileContent ( configObject , this . fs , base ) ;
880- const expFiles = configParseResult . fileNames ;
879+ this . expectedFilePaths = new Set ( configParseResult . fileNames ) ;
881880
882881 const options = configParseResult . options ;
883882 if ( / ( ^ | \/ ) j s c o n f i g \. j s o n $ / . test ( this . configFilePath ) ) {
@@ -890,7 +889,6 @@ export class ProjectConfiguration {
890889 this . fs . path ,
891890 options ,
892891 this . fs ,
893- expFiles ,
894892 this . versions ,
895893 this . logger
896894 ) ;
@@ -922,9 +920,10 @@ export class ProjectConfiguration {
922920 return ;
923921 }
924922
923+ // Add all global declaration files from the workspace and all declarations from the project
925924 for ( const uri of this . fs . uris ( ) ) {
926925 const fileName = uri2path ( uri ) ;
927- if ( isGlobalTSFile ( fileName ) || ( ! isDependencyFile ( fileName ) && isDeclarationFile ( fileName ) ) ) {
926+ if ( isGlobalTSFile ( fileName ) || ( isDeclarationFile ( fileName ) && this . expectedFilePaths . has ( toUnixPath ( fileName ) ) ) ) {
928927 const sourceFile = program . getSourceFile ( fileName ) ;
929928 if ( ! sourceFile ) {
930929 this . getHost ( ) . addFile ( fileName ) ;
@@ -966,7 +965,7 @@ export class ProjectConfiguration {
966965 if ( ! program ) {
967966 return ;
968967 }
969- for ( const fileName of ( this . getHost ( ) . expectedFilePaths || [ ] ) ) {
968+ for ( const fileName of this . expectedFilePaths ) {
970969 const sourceFile = program . getSourceFile ( fileName ) ;
971970 if ( ! sourceFile ) {
972971 this . getHost ( ) . addFile ( fileName ) ;
0 commit comments