Path: blob/main/src/vs/workbench/api/common/extHostApiDeprecationService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';6import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';7import { ILogService } from '../../../platform/log/common/log.js';8import * as extHostProtocol from './extHost.protocol.js';9import { IExtHostRpcService } from './extHostRpcService.js';1011export interface IExtHostApiDeprecationService {12readonly _serviceBrand: undefined;1314report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void;15}1617export const IExtHostApiDeprecationService = createDecorator<IExtHostApiDeprecationService>('IExtHostApiDeprecationService');1819export class ExtHostApiDeprecationService implements IExtHostApiDeprecationService {2021declare readonly _serviceBrand: undefined;2223private readonly _reportedUsages = new Set<string>();24private readonly _telemetryShape: extHostProtocol.MainThreadTelemetryShape;2526constructor(27@IExtHostRpcService rpc: IExtHostRpcService,28@ILogService private readonly _extHostLogService: ILogService,29) {30this._telemetryShape = rpc.getProxy(extHostProtocol.MainContext.MainThreadTelemetry);31}3233public report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void {34const key = this.getUsageKey(apiId, extension);35if (this._reportedUsages.has(key)) {36return;37}38this._reportedUsages.add(key);3940if (extension.isUnderDevelopment) {41this._extHostLogService.warn(`[Deprecation Warning] '${apiId}' is deprecated. ${migrationSuggestion}`);42}4344type DeprecationTelemetry = {45extensionId: string;46apiId: string;47};48type DeprecationTelemetryMeta = {49extensionId: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The id of the extension that is using the deprecated API' };50apiId: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The id of the deprecated API' };51owner: 'mjbvz';52comment: 'Helps us gain insights on extensions using deprecated API so we can assist in migration to new API';53};54this._telemetryShape.$publicLog2<DeprecationTelemetry, DeprecationTelemetryMeta>('extHostDeprecatedApiUsage', {55extensionId: extension.identifier.value,56apiId: apiId,57});58}5960private getUsageKey(apiId: string, extension: IExtensionDescription): string {61return `${apiId}-${extension.identifier.value}`;62}63}646566export const NullApiDeprecationService = Object.freeze(new class implements IExtHostApiDeprecationService {67declare readonly _serviceBrand: undefined;6869public report(_apiId: string, _extension: IExtensionDescription, _warningMessage: string): void {70// noop71}72}());737475