Skip to content

Commit ceabc70

Browse files
Properly ignore large projects/solutions when processing diagnostics
1 parent 41be44a commit ceabc70

File tree

1 file changed

+53
-18
lines changed

1 file changed

+53
-18
lines changed

src/features/diagnosticsProvider.ts

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ export class Advisor {
2121

2222
constructor(server: OmnisharpServer) {
2323
this._server = server;
24+
2425
let d1 = server.onProjectChange(this._onProjectChange, this);
25-
let d2 = server.onBeforePackageRestore(this._onBeforePackageRestore, this);
26-
let d3 = server.onPackageRestore(this._onPackageRestore, this);
27-
this._disposable = Disposable.from(d1, d2, d3);
26+
let d2 = server.onProjectAdded(this._onProjectAdded, this);
27+
let d3 = server.onProjectRemoved(this._onProjectRemoved, this);
28+
let d4 = server.onBeforePackageRestore(this._onBeforePackageRestore, this);
29+
let d5 = server.onPackageRestore(this._onPackageRestore, this);
30+
this._disposable = Disposable.from(d1, d2, d3, d4, d5);
2831
}
2932

3033
public dispose() {
@@ -42,15 +45,42 @@ export class Advisor {
4245
&& !this._isHugeProject();
4346
}
4447

45-
private _onProjectChange(info: protocol.ProjectInformationResponse): void {
48+
private _updateProjectFileCount(path: string, fileCount: number): void {
49+
this._projectSourceFileCounts[path] = fileCount;
50+
}
51+
52+
private _addOrUpdateProjectFileCount(info: protocol.ProjectInformationResponse): void {
53+
if (info.DotNetProject && info.DotNetProject.SourceFiles) {
54+
this._updateProjectFileCount(info.DotNetProject.Path, info.DotNetProject.SourceFiles.length);
55+
}
56+
57+
if (info.MsBuildProject && info.MsBuildProject.SourceFiles) {
58+
this._updateProjectFileCount(info.MsBuildProject.Path, info.MsBuildProject.SourceFiles.length);
59+
}
60+
}
61+
62+
private _removeProjectFileCount(info: protocol.ProjectInformationResponse): void {
4663
if (info.DotNetProject && info.DotNetProject.SourceFiles) {
47-
this._projectSourceFileCounts[info.DotNetProject.Path] = info.DotNetProject.SourceFiles.length;
64+
delete this._updateProjectFileCount[info.DotNetProject.Path];
4865
}
66+
4967
if (info.MsBuildProject && info.MsBuildProject.SourceFiles) {
50-
this._projectSourceFileCounts[info.MsBuildProject.Path] = info.MsBuildProject.SourceFiles.length;
68+
delete this._updateProjectFileCount[info.MsBuildProject.Path];
5169
}
5270
}
5371

72+
private _onProjectAdded(info: protocol.ProjectInformationResponse): void {
73+
this._addOrUpdateProjectFileCount(info);
74+
}
75+
76+
private _onProjectRemoved(info: protocol.ProjectInformationResponse): void {
77+
this._removeProjectFileCount(info);
78+
}
79+
80+
private _onProjectChange(info: protocol.ProjectInformationResponse): void {
81+
this._addOrUpdateProjectFileCount(info);
82+
}
83+
5484
private _onBeforePackageRestore(): void {
5585
this._packageRestoreCounter += 1;
5686
}
@@ -59,22 +89,25 @@ export class Advisor {
5989
this._packageRestoreCounter -= 1;
6090
}
6191

62-
private _isServerStarted(): boolean {
63-
return this._server.isRunning();
64-
}
65-
6692
private _isRestoringPackages(): boolean {
6793
return this._packageRestoreCounter > 0;
6894
}
6995

96+
private _isServerStarted(): boolean {
97+
return this._server.isRunning();
98+
}
99+
70100
private _isHugeProject(): boolean {
71101
let sourceFileCount = 0;
72102
for (let key in this._projectSourceFileCounts) {
73103
sourceFileCount += this._projectSourceFileCounts[key];
74104
if (sourceFileCount > 1000) {
105+
console.log(`_isHugeProject = true (${sourceFileCount})`);
75106
return true;
76107
}
77108
}
109+
110+
console.log(`_isHugeProject = false (${sourceFileCount})`);
78111
return false;
79112
}
80113
}
@@ -143,15 +176,16 @@ class DiagnosticsProvider extends AbstractSupport {
143176

144177
private _validateDocument(document: TextDocument): void {
145178

146-
if (!this._validationAdvisor.shouldValidateFiles()) {
147-
return;
148-
}
149-
179+
// If we've already started computing for this document, cancel that work.
150180
let key = document.uri.toString();
151181
if (this._documentValidations[key]) {
152182
this._documentValidations[key].cancel();
153183
}
154184

185+
if (!this._validationAdvisor.shouldValidateFiles()) {
186+
return;
187+
}
188+
155189
let source = new CancellationTokenSource();
156190
let handle = setTimeout(() => {
157191
serverUtils.codeCheck(this._server, { Filename: document.fileName }, source.token).then(value => {
@@ -176,17 +210,18 @@ class DiagnosticsProvider extends AbstractSupport {
176210
}
177211

178212
private _validateProject(): void {
213+
// If we've already started computing for this project, cancel that work.
214+
if (this._projectValidation) {
215+
this._projectValidation.cancel();
216+
}
179217

180218
if (!this._validationAdvisor.shouldValidateProject()) {
181219
return;
182220
}
183221

184-
if (this._projectValidation) {
185-
this._projectValidation.cancel();
186-
}
187-
188222
this._projectValidation = new CancellationTokenSource();
189223
let handle = setTimeout(() => {
224+
190225
serverUtils.codeCheck(this._server, { Filename: null }, this._projectValidation.token).then(value => {
191226

192227
let quickFixes = value.QuickFixes.sort((a, b) => a.FileName.localeCompare(b.FileName));

0 commit comments

Comments
 (0)