Skip to content

Commit ab7b688

Browse files
committed
Instead of getting default project before starting error list timer, get it at that time if no project is specified
Fixes #35794
1 parent ebbebc8 commit ab7b688

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

src/server/session.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,8 @@ namespace ts.server {
719719
this.projectService.logger.info(`got projects updated in background, updating diagnostics for ${openFiles}`);
720720
if (openFiles.length) {
721721
if (!this.suppressDiagnosticEvents && !this.noGetErrOnBackgroundUpdate) {
722-
const checkList = this.createCheckList(openFiles);
723-
724722
// For now only queue error checking for open files. We can change this to include non open files as well
725-
this.errorCheck.startNew(next => this.updateErrorCheck(next, checkList, 100, /*requireOpen*/ true));
723+
this.errorCheck.startNew(next => this.updateErrorCheck(next, openFiles, 100, /*requireOpen*/ true));
726724
}
727725

728726
// Send project changed event
@@ -870,20 +868,37 @@ namespace ts.server {
870868
}
871869

872870
/** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
873-
private updateErrorCheck(next: NextStep, checkList: PendingErrorCheck[], ms: number, requireOpen = true) {
871+
private updateErrorCheck(next: NextStep, checkList: readonly string[] | readonly PendingErrorCheck[], ms: number, requireOpen = true) {
874872
Debug.assert(!this.suppressDiagnosticEvents); // Caller's responsibility
875873

876874
const seq = this.changeSeq;
877875
const followMs = Math.min(ms, 200);
878876

879877
let index = 0;
878+
const goNext = () => {
879+
index++;
880+
if (checkList.length > index) {
881+
next.delay(followMs, checkOne);
882+
}
883+
};
880884
const checkOne = () => {
881885
if (this.changeSeq !== seq) {
882886
return;
883887
}
884888

885-
const { fileName, project } = checkList[index];
886-
index++;
889+
let item: string | PendingErrorCheck | undefined = checkList[index];
890+
if (isString(item)) {
891+
// Find out project for the file name
892+
item = this.toPendingErrorCheck(item);
893+
if (!item) {
894+
// Ignore file if there is no project for the file
895+
goNext();
896+
return;
897+
}
898+
}
899+
900+
const { fileName, project } = item;
901+
887902
// Ensure the project is upto date before checking if this file is present in the project
888903
updateProjectIfDirty(project);
889904
if (!project.containsFile(fileName, requireOpen)) {
@@ -901,11 +916,6 @@ namespace ts.server {
901916
return;
902917
}
903918

904-
const goNext = () => {
905-
if (checkList.length > index) {
906-
next.delay(followMs, checkOne);
907-
}
908-
};
909919
if (this.getPreferences(fileName).disableSuggestions) {
910920
goNext();
911921
}
@@ -1727,22 +1737,19 @@ namespace ts.server {
17271737
}
17281738
}
17291739

1730-
private createCheckList(fileNames: string[]): PendingErrorCheck[] {
1731-
return mapDefined<string, PendingErrorCheck>(fileNames, uncheckedFileName => {
1732-
const fileName = toNormalizedPath(uncheckedFileName);
1733-
const project = this.projectService.tryGetDefaultProjectForFile(fileName);
1734-
return project && { fileName, project };
1735-
});
1740+
private toPendingErrorCheck(uncheckedFileName: string): PendingErrorCheck | undefined {
1741+
const fileName = toNormalizedPath(uncheckedFileName);
1742+
const project = this.projectService.tryGetDefaultProjectForFile(fileName);
1743+
return project && { fileName, project };
17361744
}
17371745

17381746
private getDiagnostics(next: NextStep, delay: number, fileNames: string[]): void {
17391747
if (this.suppressDiagnosticEvents) {
17401748
return;
17411749
}
17421750

1743-
const checkList = this.createCheckList(fileNames);
1744-
if (checkList.length > 0) {
1745-
this.updateErrorCheck(next, checkList, delay);
1751+
if (fileNames.length > 0) {
1752+
this.updateErrorCheck(next, fileNames, delay);
17461753
}
17471754
}
17481755

src/testRunner/unittests/tsserver/cancellationToken.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ namespace ts.projectSystem {
8484
command: "geterr",
8585
arguments: { files: ["/a/missing"] }
8686
});
87-
// no files - expect 'completed' event
87+
// Queued files
88+
assert.equal(host.getOutput().length, 0, "expected 0 message");
89+
host.checkTimeoutQueueLengthAndRun(1);
90+
// Completed event since file is missing
8891
assert.equal(host.getOutput().length, 1, "expect 1 message");
8992
verifyRequestCompleted(session.getSeq(), 0);
9093
}

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ declare var console: {
10291029
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
10301030
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
10311031
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
1032+
assert.isTrue(service.inferredProjects[0].dirty);
10321033
}
10331034
});
10341035
});

src/testRunner/unittests/tsserver/projectErrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ namespace ts.projectSystem {
382382
}
383383
});
384384

385-
host.runQueuedImmediateCallbacks();
385+
host.checkTimeoutQueueLengthAndRun(1);
386386
assert.isFalse(hasError());
387387
checkCompleteEvent(session, 1, expectedSequenceId);
388388
session.clearMessages();

src/testRunner/unittests/tsserver/projects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ var x = 10;`
15081508
host,
15091509
expected: [
15101510
{ file: fileB, syntax: [], semantic: [], suggestion: [] },
1511-
{ file: fileSubA },
1511+
{ file: fileSubA, syntax: [], semantic: [], suggestion: [] },
15121512
],
15131513
existingTimeouts: 2,
15141514
onErrEvent: () => assert.isFalse(hasErrorMsg())

0 commit comments

Comments
 (0)