Skip to content

Commit 968332d

Browse files
authored
Warn users about too many files processed in the workspace (#13889)
1 parent 9f04a5e commit 968332d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ export class DefaultClient implements Client {
17441744
languageClient = new LanguageClient(`cpptools`, serverOptions, clientOptions);
17451745
languageClient.onNotification(DebugProtocolNotification, logDebugProtocol);
17461746
languageClient.onNotification(DebugLogNotification, logLocalized);
1747-
languageClient.onNotification(LogTelemetryNotification, (e) => this.logTelemetry(e));
1747+
languageClient.onNotification(LogTelemetryNotification, (e) => void this.logTelemetry(e));
17481748
languageClient.onNotification(ShowMessageWindowNotification, showMessageWindow);
17491749
languageClient.registerProposedFeatures();
17501750
await languageClient.start();
@@ -2778,10 +2778,38 @@ export class DefaultClient implements Client {
27782778
}
27792779
}
27802780

2781-
private logTelemetry(notificationBody: TelemetryPayload): void {
2781+
private excessiveFilesWarningShown: boolean = false;
2782+
private async logTelemetry(notificationBody: TelemetryPayload): Promise<void> {
27822783
if (notificationBody.event === "includeSquiggles" && this.configurationProvider && notificationBody.properties) {
27832784
notificationBody.properties["providerId"] = this.configurationProvider;
27842785
}
2786+
2787+
const showExcessiveFilesWarning = new PersistentWorkspaceState<boolean>('CPP.showExcessiveFilesWarning', true);
2788+
if (!this.excessiveFilesWarningShown && showExcessiveFilesWarning.Value && notificationBody.event === 'ParsingStats') {
2789+
const filesDiscovered = notificationBody.metrics?.filesDiscovered ?? 0;
2790+
const parsableFiles = notificationBody.metrics?.parsableFiles ?? 0;
2791+
if (filesDiscovered > 250000 || parsableFiles > 100000) {
2792+
// According to telemetry, less than 3% of workspaces have this many files so it seems like a reasonable threshold.
2793+
2794+
const message = localize(
2795+
"parsing.stats.large.project",
2796+
'Enumerated {0} files with {1} C/C++ source files detected. You may want to consider excluding some files for better performance.',
2797+
filesDiscovered,
2798+
parsableFiles);
2799+
const learnMore = localize('learn.more', 'Learn More');
2800+
const dontShowAgain = localize('dont.show.again', 'Don\'t Show Again');
2801+
2802+
// We only want to show this once per session.
2803+
this.excessiveFilesWarningShown = true;
2804+
const response = await vscode.window.showInformationMessage(message, learnMore, dontShowAgain);
2805+
2806+
if (response === dontShowAgain) {
2807+
showExcessiveFilesWarning.Value = false;
2808+
} else if (response === learnMore) {
2809+
void vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=2333292'));
2810+
}
2811+
}
2812+
}
27852813
telemetry.logLanguageServerEvent(notificationBody.event, notificationBody.properties, notificationBody.metrics);
27862814
}
27872815

0 commit comments

Comments
 (0)