Skip to content

Commit 496b18e

Browse files
committed
Report file change detected only once when save takes place multiple times before timeout
1 parent 828279b commit 496b18e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/compiler/tsbuild.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ namespace ts {
507507
const configFileCache = createConfigFileCache(host);
508508
let context = createBuildContext(defaultOptions);
509509
let timerToBuildInvalidatedProject: any;
510+
let reportFileChangeDetected = false;
510511

511512
const existingWatchersForWildcards = createMap<WildcardDirectoryWatcher>();
512513
return {
@@ -584,7 +585,7 @@ namespace ts {
584585
}
585586

586587
function invalidateProjectAndScheduleBuilds(resolved: ResolvedConfigFileName) {
587-
reportWatchStatus(Diagnostics.File_change_detected_Starting_incremental_compilation);
588+
reportFileChangeDetected = true;
588589
invalidateProject(resolved);
589590
scheduleBuildInvalidatedProject();
590591
}
@@ -817,6 +818,10 @@ namespace ts {
817818

818819
function buildInvalidatedProject() {
819820
timerToBuildInvalidatedProject = undefined;
821+
if (reportFileChangeDetected) {
822+
reportFileChangeDetected = false;
823+
reportWatchStatus(Diagnostics.File_change_detected_Starting_incremental_compilation);
824+
}
820825
const buildProject = context.getNextInvalidatedProject();
821826
buildSomeProjects(p => p === buildProject);
822827
if (context.hasPendingInvalidatedProjects()) {

src/testRunner/unittests/tsbuildWatchMode.ts

+13
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,22 @@ export class someClass { }`);
112112
// Another change requeues and builds it
113113
verifyChange(core[1].content);
114114

115+
// Two changes together report only single time message: File change detected. Starting incremental compilation...
116+
const outputFileStamps = getOutputFileStamps(host);
117+
const change1 = `${core[1].content}
118+
export class someClass { }`;
119+
host.writeFile(core[1].path, change1);
120+
host.writeFile(core[1].path, `${change1}
121+
export class someClass2 { }`);
122+
verifyChangeAfterTimeout(outputFileStamps);
123+
115124
function verifyChange(coreContent: string) {
116125
const outputFileStamps = getOutputFileStamps(host);
117126
host.writeFile(core[1].path, coreContent);
127+
verifyChangeAfterTimeout(outputFileStamps);
128+
}
129+
130+
function verifyChangeAfterTimeout(outputFileStamps: OutputFileStamp[]) {
118131
host.checkTimeoutQueueLengthAndRun(1); // Builds core
119132
const changedCore = getOutputFileStamps(host);
120133
verifyChangedFiles(changedCore, outputFileStamps, [

0 commit comments

Comments
 (0)