Skip to content

Commit 62664fd

Browse files
author
zhengbli
committed
Add timer for batch processing directory changes
1 parent def268c commit 62664fd

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/server/editorServices.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ namespace ts.server {
503503
// number becomes 0 for a watcher, then we should close it.
504504
directoryWatchersRefCount: ts.Map<number> = {};
505505
hostConfiguration: HostConfiguration;
506+
timerForDetectingProjectFilelistChanges: Map<NodeJS.Timer> = {};
506507

507508
constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) {
508509
// ts.disableIncrementalParsing = true;
@@ -557,6 +558,20 @@ namespace ts.server {
557558
}
558559

559560
this.log("Detected source file changes: " + fileName);
561+
this.startTimerForDetectingProjectFilelistChanges(project);
562+
}
563+
564+
startTimerForDetectingProjectFilelistChanges(project: Project) {
565+
if (this.timerForDetectingProjectFilelistChanges[project.projectFilename]) {
566+
clearTimeout(this.timerForDetectingProjectFilelistChanges[project.projectFilename]);
567+
}
568+
this.timerForDetectingProjectFilelistChanges[project.projectFilename] = setTimeout(
569+
() => this.handleProjectFilelistChanges(project),
570+
250
571+
);
572+
}
573+
574+
handleProjectFilelistChanges(project: Project) {
560575
let { succeeded, projectOptions, error } = this.configFileToProjectOptions(project.projectFilename);
561576
let newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f)));
562577
let currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f)));

0 commit comments

Comments
 (0)