From c2f453b8fb141d8015e328a2326406b0f70858ac Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 15 Jan 2016 14:58:04 -0800 Subject: [PATCH 1/2] Fix the getCanonicalFileName in sys.ts and also check null value in file watcher call back --- src/compiler/sys.ts | 8 ++++++-- src/server/editorServices.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index e6f908d250a72..1a97e9c8d0afc 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -378,7 +378,11 @@ namespace ts { */ 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); + /* tslint:disable:no-null */ + const filePath = relativefileName === undefined || relativefileName === null + ? undefined + : toPath(relativefileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); + /* tslint:enable:no-null */ if (eventName === "change" && fileWatcherCallbacks.contains(filePath)) { for (const fileCallback of fileWatcherCallbacks.get(filePath)) { fileCallback(filePath); @@ -460,7 +464,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), From c244306514a7e338a17c2a1b9f2e3959308435cb Mon Sep 17 00:00:00 2001 From: zhengbli Date: Fri, 15 Jan 2016 16:55:25 -0800 Subject: [PATCH 2/2] address CR feedback: use typeof check instead of checking undefined and null value --- src/compiler/sys.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 1a97e9c8d0afc..bf25d39aa4395 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -376,13 +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" - /* tslint:disable:no-null */ - const filePath = relativefileName === undefined || relativefileName === null + const filePath = typeof relativeFileName !== "string" ? undefined - : toPath(relativefileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); - /* tslint:enable:no-null */ + : toPath(relativeFileName, baseDirPath, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); if (eventName === "change" && fileWatcherCallbacks.contains(filePath)) { for (const fileCallback of fileWatcherCallbacks.get(filePath)) { fileCallback(filePath);