From fb4b533d9352f32297ae77b5ba6d7485bbbf69aa Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 21 Aug 2023 17:01:53 +0200 Subject: [PATCH] extracting the method _increaseDiagnosticCodeCount to avoid duplication --- .../src/languageFeatures/diagnostics.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/extensions/typescript-language-features/src/languageFeatures/diagnostics.ts b/extensions/typescript-language-features/src/languageFeatures/diagnostics.ts index 57f1d257bb2..0743d34f0e2 100644 --- a/extensions/typescript-language-features/src/languageFeatures/diagnostics.ts +++ b/extensions/typescript-language-features/src/languageFeatures/diagnostics.ts @@ -177,6 +177,13 @@ class DiagnosticsTelemetryManager extends Disposable { this._timeout = setTimeout(() => { uris.forEach((uri) => this._updateDiagnosticCodes(uri)); }, 5000); } + private _increaseDiagnosticCodeCount(code: string | number | undefined) { + if (code === undefined) { + return; + } + this._diagnosticCodesMap.set(Number(code), (this._diagnosticCodesMap.get(Number(code)) || 0) + 1); + } + private _updateDiagnosticCodes(uri: vscode.Uri) { const uriString = uri.toString(); const previousDiagnostics = this._diagnosticSnapshotsMap.get(uriString); @@ -185,11 +192,7 @@ class DiagnosticsTelemetryManager extends Disposable { const diagnosticsDiff = currentDiagnostics.filter((diagnostic) => !previousDiagnostics?.some((previousDiagnostic) => equals(diagnostic, previousDiagnostic))); diagnosticsDiff.forEach((diagnostic) => { const code = diagnostic.code; - if (typeof code === 'string' || typeof code === 'number') { - this._diagnosticCodesMap.set(Number(code), (this._diagnosticCodesMap.get(Number(code)) || 0) + 1); - } else if (code !== undefined) { - this._diagnosticCodesMap.set(Number(code.value), (this._diagnosticCodesMap.get(Number(code.value)) || 0) + 1); - } + this._increaseDiagnosticCodeCount(typeof code === 'string' || typeof code === 'number' ? code : code?.value); }); }