Skip to content

Commit c2f453b

Browse files
committed
Fix the getCanonicalFileName in sys.ts and also check null value in file watcher call back
1 parent efc573f commit c2f453b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/compiler/sys.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ namespace ts {
378378
*/
379379
function fileEventHandler(eventName: string, relativefileName: string, baseDirPath: Path) {
380380
// When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined"
381-
const filePath = relativefileName === undefined ? undefined : toPath(relativefileName, baseDirPath, getCanonicalPath);
381+
/* tslint:disable:no-null */
382+
const filePath = relativefileName === undefined || relativefileName === null
383+
? undefined
384+
: toPath(relativefileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
385+
/* tslint:enable:no-null */
382386
if (eventName === "change" && fileWatcherCallbacks.contains(filePath)) {
383387
for (const fileCallback of fileWatcherCallbacks.get(filePath)) {
384388
fileCallback(filePath);
@@ -460,7 +464,7 @@ namespace ts {
460464
}
461465

462466
function getCanonicalPath(path: string): string {
463-
return useCaseSensitiveFileNames ? path.toLowerCase() : path;
467+
return useCaseSensitiveFileNames ? path : path.toLowerCase();
464468
}
465469

466470
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {

src/server/editorServices.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,9 @@ namespace ts.server {
10021002
info.setFormatOptions(this.getFormatCodeOptions());
10031003
this.filenameToScriptInfo[fileName] = info;
10041004
if (!info.isOpen) {
1005-
info.fileWatcher = this.host.watchFile(<Path>fileName, _ => { this.watchedFileChanged(fileName); });
1005+
info.fileWatcher = this.host.watchFile(
1006+
toPath(fileName, fileName, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
1007+
_ => { this.watchedFileChanged(fileName); });
10061008
}
10071009
}
10081010
}
@@ -1215,7 +1217,9 @@ namespace ts.server {
12151217
}
12161218
}
12171219
project.finishGraph();
1218-
project.projectFileWatcher = this.host.watchFile(<Path>configFilename, _ => this.watchedProjectConfigFileChanged(project));
1220+
project.projectFileWatcher = this.host.watchFile(
1221+
toPath(configFilename, configFilename, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
1222+
_ => this.watchedProjectConfigFileChanged(project));
12191223
this.log("Add recursive watcher for: " + ts.getDirectoryPath(configFilename));
12201224
project.directoryWatcher = this.host.watchDirectory(
12211225
ts.getDirectoryPath(configFilename),

0 commit comments

Comments
 (0)