diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index e6f908d250a72..bf25d39aa4395 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -376,9 +376,11 @@ namespace ts { /** * @param watcherPath is the path from which the watcher is triggered. */ - function fileEventHandler(eventName: string, relativefileName: string, baseDirPath: Path) { + function fileEventHandler(eventName: string, relativeFileName: string, baseDirPath: Path) { // When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined" - const filePath = relativefileName === undefined ? undefined : toPath(relativefileName, baseDirPath, getCanonicalPath); + const filePath = typeof relativeFileName !== "string" + ? undefined + : toPath(relativeFileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); if (eventName === "change" && fileWatcherCallbacks.contains(filePath)) { for (const fileCallback of fileWatcherCallbacks.get(filePath)) { fileCallback(filePath); @@ -460,7 +462,7 @@ namespace ts { } function getCanonicalPath(path: string): string { - return useCaseSensitiveFileNames ? path.toLowerCase() : path; + return useCaseSensitiveFileNames ? path : path.toLowerCase(); } function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index fd9f1077dd96e..7cc3a6c96a67c 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1002,7 +1002,9 @@ namespace ts.server { info.setFormatOptions(this.getFormatCodeOptions()); this.filenameToScriptInfo[fileName] = info; if (!info.isOpen) { - info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); }); + info.fileWatcher = this.host.watchFile( + toPath(fileName, fileName, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)), + _ => { this.watchedFileChanged(fileName); }); } } } @@ -1215,7 +1217,9 @@ namespace ts.server { } } project.finishGraph(); - project.projectFileWatcher = this.host.watchFile(configFilename, _ => this.watchedProjectConfigFileChanged(project)); + project.projectFileWatcher = this.host.watchFile( + toPath(configFilename, configFilename, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)), + _ => this.watchedProjectConfigFileChanged(project)); this.log("Add recursive watcher for: " + ts.getDirectoryPath(configFilename)); project.directoryWatcher = this.host.watchDirectory( ts.getDirectoryPath(configFilename),