|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { onUnexpectedError } from 'vs/base/common/errors'; |
| 7 | +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; |
| 8 | +import { Registry } from 'vs/platform/registry/common/platform'; |
| 9 | +import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; |
| 10 | +import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; |
| 11 | +import { IExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/common/extensions'; |
| 12 | +import { EnablementState } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; |
| 13 | +import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; |
| 14 | + |
| 15 | +class BracketPairColorizer2TelemetryContribution { |
| 16 | + constructor( |
| 17 | + @IConfigurationService private readonly configurationService: IConfigurationService, |
| 18 | + @IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService, |
| 19 | + @ITelemetryService private readonly telemetryService: ITelemetryService |
| 20 | + ) { |
| 21 | + this.init().catch(onUnexpectedError); |
| 22 | + } |
| 23 | + |
| 24 | + private async init(): Promise<void> { |
| 25 | + const bracketPairColorizerId = 'coenraads.bracket-pair-colorizer-2'; |
| 26 | + |
| 27 | + await this.extensionsWorkbenchService.queryLocal(); |
| 28 | + const extension = this.extensionsWorkbenchService.installed.find(e => e.identifier.id === bracketPairColorizerId); |
| 29 | + if ( |
| 30 | + !extension || |
| 31 | + ((extension.enablementState !== EnablementState.EnabledGlobally) && |
| 32 | + (extension.enablementState !== EnablementState.EnabledWorkspace)) |
| 33 | + ) { |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + const nativeBracketPairColorizationEnabledKey = 'editor.bracketPairColorization.enabled'; |
| 38 | + const nativeColorizationEnabled = !!this.configurationService.getValue(nativeBracketPairColorizationEnabledKey); |
| 39 | + |
| 40 | + type BracketPairColorizer2InstalledClassification = { |
| 41 | + owner: 'hediet'; |
| 42 | + nativeColorizationEnabled: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Whether or not built-in bracket pair colorization is being used' }; |
| 43 | + comment: 'We use this to understand how many users have the bracket pair colorizer extension installed (and how many of them have native bracket pair colorization enabled), as the extension does not do anything if native bracket pair colorization is enabled.'; |
| 44 | + }; |
| 45 | + type BracketPairColorizer2Event = { |
| 46 | + nativeColorizationEnabled: boolean; |
| 47 | + }; |
| 48 | + this.telemetryService.publicLog2<BracketPairColorizer2Event, BracketPairColorizer2InstalledClassification>('bracketPairColorizer2Usage', { |
| 49 | + nativeColorizationEnabled |
| 50 | + }); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(BracketPairColorizer2TelemetryContribution, LifecyclePhase.Restored); |
| 55 | + |
0 commit comments