Skip to content

Commit bdd8d4d

Browse files
author
Andy Hanson
committed
Simplify parameters to updateProjectStructure and updateErrorCheck
1 parent fd2dd2e commit bdd8d4d

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/server/session.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ namespace ts.server {
343343
case ContextEvent:
344344
const { project, fileName } = event.data;
345345
this.projectService.logger.info(`got context event, updating diagnostics for ${fileName}`);
346-
this.errorCheck.startNew(next => this.updateErrorCheck(next, [{ fileName, project }], this.changeSeq, (n) => n === this.changeSeq, 100));
346+
this.errorCheck.startNew(next => this.updateErrorCheck(next, [{ fileName, project }], 100));
347347
break;
348348
case ConfigFileDiagEvent:
349349
const { triggerFile, configFileName, diagnostics } = event.data;
@@ -459,22 +459,23 @@ namespace ts.server {
459459
}
460460
}
461461

462-
private updateProjectStructure(seq: number, matchSeq: (seq: number) => boolean, ms = 1500) {
462+
private updateProjectStructure() {
463+
const ms = 1500;
464+
const seq = this.changeSeq;
463465
this.host.setTimeout(() => {
464-
if (matchSeq(seq)) {
466+
if (this.changeSeq === seq) {
465467
this.projectService.refreshInferredProjects();
466468
}
467469
}, ms);
468470
}
469471

470-
private updateErrorCheck(next: NextStep, checkList: PendingErrorCheck[], seq: number, matchSeq: (seq: number) => boolean, ms = 1500, followMs = 200, requireOpen = true) {
471-
if (followMs > ms) {
472-
followMs = ms;
473-
}
472+
private updateErrorCheck(next: NextStep, checkList: PendingErrorCheck[], ms: number, requireOpen = true) {
473+
const seq = this.changeSeq;
474+
const followMs = Math.min(ms, 200);
474475

475476
let index = 0;
476477
const checkOne = () => {
477-
if (matchSeq(seq)) {
478+
if (this.changeSeq === seq) {
478479
const checkSpec = checkList[index];
479480
index++;
480481
if (checkSpec.project.containsFile(checkSpec.fileName, requireOpen)) {
@@ -489,7 +490,7 @@ namespace ts.server {
489490
}
490491
};
491492

492-
if ((checkList.length > index) && (matchSeq(seq))) {
493+
if (checkList.length > index && this.changeSeq === seq) {
493494
next.delay(ms, checkOne);
494495
}
495496
}
@@ -1268,14 +1269,14 @@ namespace ts.server {
12681269
}
12691270

12701271
private getDiagnostics(next: NextStep, delay: number, fileNames: string[]): void {
1271-
const checkList = mapDefined(fileNames, uncheckedFileName => {
1272+
const checkList = mapDefined<string, PendingErrorCheck>(fileNames, uncheckedFileName => {
12721273
const fileName = toNormalizedPath(uncheckedFileName);
12731274
const project = this.projectService.getDefaultProjectForFile(fileName, /*refreshInferredProjects*/ true);
12741275
return project && { fileName, project };
12751276
});
12761277

12771278
if (checkList.length > 0) {
1278-
this.updateErrorCheck(next, checkList, this.changeSeq, (n) => n === this.changeSeq, delay);
1279+
this.updateErrorCheck(next, checkList, delay);
12791280
}
12801281
}
12811282

@@ -1289,7 +1290,7 @@ namespace ts.server {
12891290
scriptInfo.editContent(start, end, args.insertString);
12901291
this.changeSeq++;
12911292
}
1292-
this.updateProjectStructure(this.changeSeq, n => n === this.changeSeq);
1293+
this.updateProjectStructure();
12931294
}
12941295
}
12951296

@@ -1644,7 +1645,7 @@ namespace ts.server {
16441645
const checkList = fileNamesInProject.map(fileName => ({ fileName, project }));
16451646
// Project level error analysis runs on background files too, therefore
16461647
// doesn't require the file to be opened
1647-
this.updateErrorCheck(next, checkList, this.changeSeq, (n) => n === this.changeSeq, delay, 200, /*requireOpen*/ false);
1648+
this.updateErrorCheck(next, checkList, delay, /*requireOpen*/ false);
16481649
}
16491650
}
16501651

0 commit comments

Comments
 (0)