Skip to content

Commit 2ec92b9

Browse files
committed
Dont create script snapshots for files that arent source files
1 parent 52e867c commit 2ec92b9

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/services/services.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ namespace ts {
815815
private _compilationSettings: CompilerOptions;
816816
private currentDirectory: string;
817817

818-
constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) {
818+
constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) {
819819
// script id => script index
820820
this.currentDirectory = host.getCurrentDirectory();
821821
this.fileNameToEntry = createFileMap<HostFileInformation>();
@@ -850,22 +850,17 @@ namespace ts {
850850
return entry;
851851
}
852852

853-
private getEntry(path: Path): HostFileInformation {
853+
public getEntryByPath(path: Path): HostFileInformation {
854854
return this.fileNameToEntry.get(path);
855855
}
856856

857-
private contains(path: Path): boolean {
857+
public containsEntryByPath(path: Path): boolean {
858858
return this.fileNameToEntry.contains(path);
859859
}
860860

861-
public getOrCreateEntry(fileName: string): HostFileInformation {
862-
const path = toPath(fileName, this.currentDirectory, this.getCanonicalFileName);
863-
return this.getOrCreateEntryByPath(fileName, path);
864-
}
865-
866861
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)
869864
: this.createEntry(fileName, path);
870865
}
871866

@@ -882,12 +877,12 @@ namespace ts {
882877
}
883878

884879
public getVersion(path: Path): string {
885-
const file = this.getEntry(path);
880+
const file = this.getEntryByPath(path);
886881
return file && file.version;
887882
}
888883

889884
public getScriptSnapshot(path: Path): IScriptSnapshot {
890-
const file = this.getEntry(path);
885+
const file = this.getEntryByPath(path);
891886
return file && file.scriptSnapshot;
892887
}
893888
}
@@ -1152,12 +1147,19 @@ namespace ts {
11521147
getCurrentDirectory: () => currentDirectory,
11531148
fileExists: (fileName): boolean => {
11541149
// 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));
11561154
},
11571155
readFile: (fileName): string => {
11581156
// 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);
11611163
},
11621164
directoryExists: directoryName => {
11631165
return directoryProbablyExists(directoryName, host);

0 commit comments

Comments
 (0)