Skip to content

Commit a33bb6b

Browse files
committed
use canonical file name when asking the host if file exists
1 parent 14362b0 commit a33bb6b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/services/services.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ module ts {
16321632
private fileNameToEntry: Map<HostFileInformation>;
16331633
private _compilationSettings: CompilerOptions;
16341634

1635-
constructor(private host: LanguageServiceHost) {
1635+
constructor(private host: LanguageServiceHost, private getCanonicalFileName: (fileName: string) => string) {
16361636
// script id => script index
16371637
this.fileNameToEntry = {};
16381638

@@ -1650,6 +1650,10 @@ module ts {
16501650
return this._compilationSettings;
16511651
}
16521652

1653+
private normalizeFileName(fileName: string): string {
1654+
return this.getCanonicalFileName(normalizeSlashes(fileName));
1655+
}
1656+
16531657
private createEntry(fileName: string) {
16541658
let entry: HostFileInformation;
16551659
let scriptSnapshot = this.host.getScriptSnapshot(fileName);
@@ -1661,15 +1665,15 @@ module ts {
16611665
};
16621666
}
16631667

1664-
return this.fileNameToEntry[normalizeSlashes(fileName)] = entry;
1668+
return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry;
16651669
}
16661670

1667-
public getEntry(fileName: string): HostFileInformation {
1668-
return lookUp(this.fileNameToEntry, normalizeSlashes(fileName));
1671+
private getEntry(fileName: string): HostFileInformation {
1672+
return lookUp(this.fileNameToEntry, this.normalizeFileName(fileName));
16691673
}
16701674

1671-
public contains(fileName: string): boolean {
1672-
return hasProperty(this.fileNameToEntry, normalizeSlashes(fileName));
1675+
private contains(fileName: string): boolean {
1676+
return hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName));
16731677
}
16741678

16751679
public getOrCreateEntry(fileName: string): HostFileInformation {
@@ -1684,8 +1688,10 @@ module ts {
16841688
let fileNames: string[] = [];
16851689

16861690
forEachKey(this.fileNameToEntry, key => {
1687-
if (hasProperty(this.fileNameToEntry, key) && this.fileNameToEntry[key])
1688-
fileNames.push(key);
1691+
let entry = this.getEntry(key);
1692+
if (entry) {
1693+
fileNames.push(entry.hostFileName);
1694+
}
16891695
});
16901696

16911697
return fileNames;
@@ -2387,7 +2393,7 @@ module ts {
23872393

23882394
function synchronizeHostData(): void {
23892395
// Get a fresh cache of the host information
2390-
let hostCache = new HostCache(host);
2396+
let hostCache = new HostCache(host, getCanonicalFileName);
23912397

23922398
// If the program is already up-to-date, we can reuse it
23932399
if (programUpToDate()) {
@@ -2408,7 +2414,7 @@ module ts {
24082414
let newProgram = createProgram(hostCache.getRootFileNames(), newSettings, {
24092415
getSourceFile: getOrCreateSourceFile,
24102416
getCancellationToken: () => cancellationToken,
2411-
getCanonicalFileName: (fileName) => useCaseSensitivefileNames ? fileName : fileName.toLowerCase(),
2417+
getCanonicalFileName,
24122418
useCaseSensitiveFileNames: () => useCaseSensitivefileNames,
24132419
getNewLine: () => host.getNewLine ? host.getNewLine() : "\r\n",
24142420
getDefaultLibFileName: (options) => host.getDefaultLibFileName(options),

0 commit comments

Comments
 (0)