@@ -815,7 +815,7 @@ namespace ts {
815
815
private _compilationSettings : CompilerOptions ;
816
816
private currentDirectory : string ;
817
817
818
- constructor ( private host : LanguageServiceHost , private getCanonicalFileName : ( fileName : string ) => string ) {
818
+ constructor ( private host : LanguageServiceHost , getCanonicalFileName : ( fileName : string ) => string ) {
819
819
// script id => script index
820
820
this . currentDirectory = host . getCurrentDirectory ( ) ;
821
821
this . fileNameToEntry = createFileMap < HostFileInformation > ( ) ;
@@ -850,22 +850,17 @@ namespace ts {
850
850
return entry ;
851
851
}
852
852
853
- private getEntry ( path : Path ) : HostFileInformation {
853
+ public getEntryByPath ( path : Path ) : HostFileInformation {
854
854
return this . fileNameToEntry . get ( path ) ;
855
855
}
856
856
857
- private contains ( path : Path ) : boolean {
857
+ public containsEntryByPath ( path : Path ) : boolean {
858
858
return this . fileNameToEntry . contains ( path ) ;
859
859
}
860
860
861
- public getOrCreateEntry ( fileName : string ) : HostFileInformation {
862
- const path = toPath ( fileName , this . currentDirectory , this . getCanonicalFileName ) ;
863
- return this . getOrCreateEntryByPath ( fileName , path ) ;
864
- }
865
-
866
861
public getOrCreateEntryByPath ( fileName : string , path : Path ) : HostFileInformation {
867
- return this . contains ( path )
868
- ? this . getEntry ( path )
862
+ return this . containsEntryByPath ( path )
863
+ ? this . getEntryByPath ( path )
869
864
: this . createEntry ( fileName , path ) ;
870
865
}
871
866
@@ -882,12 +877,12 @@ namespace ts {
882
877
}
883
878
884
879
public getVersion ( path : Path ) : string {
885
- const file = this . getEntry ( path ) ;
880
+ const file = this . getEntryByPath ( path ) ;
886
881
return file && file . version ;
887
882
}
888
883
889
884
public getScriptSnapshot ( path : Path ) : IScriptSnapshot {
890
- const file = this . getEntry ( path ) ;
885
+ const file = this . getEntryByPath ( path ) ;
891
886
return file && file . scriptSnapshot ;
892
887
}
893
888
}
@@ -1152,12 +1147,19 @@ namespace ts {
1152
1147
getCurrentDirectory : ( ) => currentDirectory ,
1153
1148
fileExists : ( fileName ) : boolean => {
1154
1149
// stub missing host functionality
1155
- return hostCache . getOrCreateEntry ( fileName ) !== undefined ;
1150
+ const path = toPath ( fileName , currentDirectory , getCanonicalFileName ) ;
1151
+ return hostCache . containsEntryByPath ( path ) ?
1152
+ ! ! hostCache . getEntryByPath ( path ) :
1153
+ ( host . fileExists && host . fileExists ( fileName ) ) ;
1156
1154
} ,
1157
1155
readFile : ( fileName ) : string => {
1158
1156
// stub missing host functionality
1159
- const entry = hostCache . getOrCreateEntry ( fileName ) ;
1160
- return entry && entry . scriptSnapshot . getText ( 0 , entry . scriptSnapshot . getLength ( ) ) ;
1157
+ const path = toPath ( fileName , currentDirectory , getCanonicalFileName ) ;
1158
+ if ( hostCache . containsEntryByPath ( path ) ) {
1159
+ const entry = hostCache . getEntryByPath ( path ) ;
1160
+ return entry && entry . scriptSnapshot . getText ( 0 , entry . scriptSnapshot . getLength ( ) ) ;
1161
+ }
1162
+ return host . readFile && host . readFile ( fileName ) ;
1161
1163
} ,
1162
1164
directoryExists : directoryName => {
1163
1165
return directoryProbablyExists ( directoryName , host ) ;
0 commit comments