Skip to content

Commit 8497131

Browse files
committed
Merge branch 'ShyykoSerhiy-master'
2 parents cbe2f3d + c626016 commit 8497131

3 files changed

Lines changed: 29 additions & 18 deletions

File tree

src/compiler/sys.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ts {
88
write(s: string): void;
99
readFile(path: string, encoding?: string): string;
1010
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
11-
watchFile?(path: string, callback: (path: string) => void): FileWatcher;
11+
watchFile?(path: string, callback: (path: string, removed: boolean) => void): FileWatcher;
1212
resolvePath(path: string): string;
1313
fileExists(path: string): boolean;
1414
directoryExists(path: string): boolean;
@@ -292,11 +292,16 @@ namespace ts {
292292
};
293293

294294
function fileChanged(curr: any, prev: any) {
295+
// mtime.getTime() equals 0 if file was removed
296+
if (curr.mtime.getTime() === 0) {
297+
callback(fileName, /* removed */ true);
298+
return;
299+
}
295300
if (+curr.mtime <= +prev.mtime) {
296301
return;
297302
}
298303

299-
callback(fileName);
304+
callback(fileName, /* removed */ false);
300305
}
301306
},
302307
resolvePath: function (path: string): string {

src/compiler/tsc.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace ts {
103103

104104
function reportWatchDiagnostic(diagnostic: Diagnostic) {
105105
let output = new Date().toLocaleTimeString() + " - ";
106-
106+
107107
if (diagnostic.file) {
108108
let loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
109109
output += `${ diagnostic.file.fileName }(${ loc.line + 1 },${ loc.character + 1 }): `;
@@ -113,7 +113,7 @@ namespace ts {
113113

114114
sys.write(output);
115115
}
116-
116+
117117
function padLeft(s: string, length: number) {
118118
while (s.length < length) {
119119
s = " " + s;
@@ -275,7 +275,7 @@ namespace ts {
275275
let sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
276276
if (sourceFile && compilerOptions.watch) {
277277
// Attach a file watcher
278-
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile));
278+
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (fileName, removed) => sourceFileChanged(sourceFile, removed));
279279
}
280280
return sourceFile;
281281
}
@@ -297,9 +297,15 @@ namespace ts {
297297
}
298298

299299
// If a source file changes, mark it as unwatched and start the recompilation timer
300-
function sourceFileChanged(sourceFile: SourceFile) {
300+
function sourceFileChanged(sourceFile: SourceFile, removed: boolean) {
301301
sourceFile.fileWatcher.close();
302302
sourceFile.fileWatcher = undefined;
303+
if (removed) {
304+
var index = rootFileNames.indexOf(sourceFile.fileName);
305+
if (index >= 0) {
306+
rootFileNames.splice(index, 1);
307+
}
308+
}
303309
startTimer();
304310
}
305311

@@ -531,8 +537,8 @@ namespace ts {
531537

532538
return;
533539

534-
function serializeCompilerOptions(options: CompilerOptions): Map<string|number|boolean> {
535-
let result: Map<string|number|boolean> = {};
540+
function serializeCompilerOptions(options: CompilerOptions): Map<string | number | boolean> {
541+
let result: Map<string | number | boolean> = {};
536542
let optionsNameMap = getOptionNameMap().optionNameMap;
537543

538544
for (let name in options) {

src/server/server.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ts.server {
1111
input: process.stdin,
1212
output: process.stdout,
1313
terminal: false,
14-
});
14+
});
1515

1616
class Logger implements ts.server.Logger {
1717
fd = -1;
@@ -58,7 +58,7 @@ namespace ts.server {
5858
isVerbose() {
5959
return this.loggingEnabled() && (this.level == "verbose");
6060
}
61-
61+
6262

6363
msg(s: string, type = "Err") {
6464
if (this.fd < 0) {
@@ -85,7 +85,7 @@ namespace ts.server {
8585

8686
interface WatchedFile {
8787
fileName: string;
88-
callback: (fileName: string) => void;
88+
callback: (fileName: string, removed: boolean) => void;
8989
mtime: Date;
9090
}
9191

@@ -121,11 +121,11 @@ namespace ts.server {
121121

122122
fs.stat(watchedFile.fileName,(err, stats) => {
123123
if (err) {
124-
watchedFile.callback(watchedFile.fileName);
124+
watchedFile.callback(watchedFile.fileName, /* removed */ false);
125125
}
126126
else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) {
127127
watchedFile.mtime = WatchedFileSet.getModifiedTime(watchedFile.fileName);
128-
watchedFile.callback(watchedFile.fileName);
128+
watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0);
129129
}
130130
});
131131
}
@@ -153,7 +153,7 @@ namespace ts.server {
153153
}, this.interval);
154154
}
155155

156-
addFile(fileName: string, callback: (fileName: string) => void ): WatchedFile {
156+
addFile(fileName: string, callback: (fileName: string, removed: boolean) => void ): WatchedFile {
157157
var file: WatchedFile = {
158158
fileName,
159159
callback,
@@ -170,7 +170,7 @@ namespace ts.server {
170170
removeFile(file: WatchedFile) {
171171
this.watchedFiles = WatchedFileSet.copyListRemovingItem(file, this.watchedFiles);
172172
}
173-
}
173+
}
174174

175175
class IOSession extends Session {
176176
constructor(host: ServerHost, logger: ts.server.Logger) {
@@ -243,11 +243,11 @@ namespace ts.server {
243243
// TODO: check that this location is writable
244244

245245
var logger = createLoggerFromEnv();
246-
246+
247247
// REVIEW: for now this implementation uses polling.
248248
// The advantage of polling is that it works reliably
249249
// on all os and with network mounted files.
250-
// For 90 referenced files, the average time to detect
250+
// For 90 referenced files, the average time to detect
251251
// changes is 2*msInterval (by default 5 seconds).
252252
// The overhead of this is .04 percent (1/2500) with
253253
// average pause of < 1 millisecond (and max
@@ -271,4 +271,4 @@ namespace ts.server {
271271
});
272272
// Start listening
273273
ioSession.listen();
274-
}
274+
}

0 commit comments

Comments
 (0)