Skip to content

Commit a24900e

Browse files
author
Zhengbo Li
committed
Merge pull request microsoft#6509 from zhengbli/fixPathForWatcher
Fix the getCanonicalFileName in sys.ts and also check null value in f…
2 parents 06b24ce + c244306 commit a24900e

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/compiler/sys.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,11 @@ namespace ts {
376376
/**
377377
* @param watcherPath is the path from which the watcher is triggered.
378378
*/
379-
function fileEventHandler(eventName: string, relativefileName: string, baseDirPath: Path) {
379+
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+
const filePath = typeof relativeFileName !== "string"
382+
? undefined
383+
: toPath(relativeFileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
382384
if (eventName === "change" && fileWatcherCallbacks.contains(filePath)) {
383385
for (const fileCallback of fileWatcherCallbacks.get(filePath)) {
384386
fileCallback(filePath);
@@ -460,7 +462,7 @@ namespace ts {
460462
}
461463

462464
function getCanonicalPath(path: string): string {
463-
return useCaseSensitiveFileNames ? path.toLowerCase() : path;
465+
return useCaseSensitiveFileNames ? path : path.toLowerCase();
464466
}
465467

466468
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)