Fix the getCanonicalFileName in sys.ts and also check null value in file watcher call back

This commit is contained in:
zhengbli 2016-01-15 14:58:04 -08:00
parent efc573f263
commit c2f453b8fb
2 changed files with 12 additions and 4 deletions

View file

@ -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[] {

View file

@ -1002,7 +1002,9 @@ namespace ts.server {
info.setFormatOptions(this.getFormatCodeOptions());
this.filenameToScriptInfo[fileName] = info;
if (!info.isOpen) {
info.fileWatcher = this.host.watchFile(<Path>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(<Path>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),