Skip to content

Commit

Permalink
Instead of getting default project before starting error list timer, …
Browse files Browse the repository at this point in the history
…get it at that time if no project is specified

Fixes #35794
  • Loading branch information
sheetalkamat committed Jan 17, 2020
1 parent 78072a9 commit 1740450
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
47 changes: 27 additions & 20 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,8 @@ namespace ts.server {
this.projectService.logger.info(`got projects updated in background, updating diagnostics for ${openFiles}`);
if (openFiles.length) {
if (!this.suppressDiagnosticEvents && !this.noGetErrOnBackgroundUpdate) {
const checkList = this.createCheckList(openFiles);

// For now only queue error checking for open files. We can change this to include non open files as well
this.errorCheck.startNew(next => this.updateErrorCheck(next, checkList, 100, /*requireOpen*/ true));
this.errorCheck.startNew(next => this.updateErrorCheck(next, openFiles, 100, /*requireOpen*/ true));
}

// Send project changed event
Expand Down Expand Up @@ -870,20 +868,37 @@ namespace ts.server {
}

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

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

let index = 0;
const goNext = () => {
index++;
if (checkList.length > index) {
next.delay(followMs, checkOne);
}
};
const checkOne = () => {
if (this.changeSeq !== seq) {
return;
}

const { fileName, project } = checkList[index];
index++;
let item: string | PendingErrorCheck | undefined = checkList[index];
if (isString(item)) {
// Find out project for the file name
item = this.toPendingErrorCheck(item);
if (!item) {
// Ignore file if there is no project for the file
goNext();
return;
}
}

const { fileName, project } = item;

// Ensure the project is upto date before checking if this file is present in the project
updateProjectIfDirty(project);
if (!project.containsFile(fileName, requireOpen)) {
Expand All @@ -901,11 +916,6 @@ namespace ts.server {
return;
}

const goNext = () => {
if (checkList.length > index) {
next.delay(followMs, checkOne);
}
};
if (this.getPreferences(fileName).disableSuggestions) {
goNext();
}
Expand Down Expand Up @@ -1727,22 +1737,19 @@ namespace ts.server {
}
}

private createCheckList(fileNames: string[]): PendingErrorCheck[] {
return mapDefined<string, PendingErrorCheck>(fileNames, uncheckedFileName => {
const fileName = toNormalizedPath(uncheckedFileName);
const project = this.projectService.tryGetDefaultProjectForFile(fileName);
return project && { fileName, project };
});
private toPendingErrorCheck(uncheckedFileName: string): PendingErrorCheck | undefined {
const fileName = toNormalizedPath(uncheckedFileName);
const project = this.projectService.tryGetDefaultProjectForFile(fileName);
return project && { fileName, project };
}

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

const checkList = this.createCheckList(fileNames);
if (checkList.length > 0) {
this.updateErrorCheck(next, checkList, delay);
if (fileNames.length > 0) {
this.updateErrorCheck(next, fileNames, delay);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/testRunner/unittests/tsserver/cancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ namespace ts.projectSystem {
command: "geterr",
arguments: { files: ["/a/missing"] }
});
// no files - expect 'completed' event
// Queued files
assert.equal(host.getOutput().length, 0, "expected 0 message");
host.checkTimeoutQueueLengthAndRun(1);
// Completed event since file is missing
assert.equal(host.getOutput().length, 1, "expect 1 message");
verifyRequestCompleted(session.getSeq(), 0);
}
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/unittests/tsserver/configuredProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ declare var console: {
checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 });
checkProjectActualFiles(service.configuredProjects.get(config.path)!, [foo.path, bar.path, fooBar.path, libFile.path, config.path]);
checkProjectActualFiles(service.inferredProjects[0], [fooBar.path, libFile.path]);
assert.isTrue(service.inferredProjects[0].dirty);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/projectErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ namespace ts.projectSystem {
}
});

host.runQueuedImmediateCallbacks();
host.checkTimeoutQueueLengthAndRun(1);
assert.isFalse(hasError());
checkCompleteEvent(session, 1, expectedSequenceId);
session.clearMessages();
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ var x = 10;`
host,
expected: [
{ file: fileB, syntax: [], semantic: [], suggestion: [] },
{ file: fileSubA },
{ file: fileSubA, syntax: [], semantic: [], suggestion: [] },
],
existingTimeouts: 2,
onErrEvent: () => assert.isFalse(hasErrorMsg())
Expand Down

0 comments on commit 1740450

Please sign in to comment.