Files
azuredatastudio/src/vs/workbench/api/common/extHostApiDeprecationService.ts
Anthony Dresser bd7aac8ee0 Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 (#8911)
* Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2

* update distro

* fix layering

* update distro

* fix tests
2020-01-22 13:42:37 -08:00

72 lines
2.7 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
export interface IExtHostApiDeprecationService {
_serviceBrand: undefined;
report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void;
}
export const IExtHostApiDeprecationService = createDecorator<IExtHostApiDeprecationService>('IExtHostApiDeprecationService');
export class ExtHostApiDeprecationService implements IExtHostApiDeprecationService {
_serviceBrand: undefined;
private readonly _reportedUsages = new Set<string>();
private readonly _telemetryShape: extHostProtocol.MainThreadTelemetryShape;
constructor(
@IExtHostRpcService rpc: IExtHostRpcService,
@ILogService private readonly _extHostLogService: ILogService,
) {
this._telemetryShape = rpc.getProxy(extHostProtocol.MainContext.MainThreadTelemetry);
}
public report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void {
const key = this.getUsageKey(apiId, extension);
if (this._reportedUsages.has(key)) {
return;
}
this._reportedUsages.add(key);
if (extension.isUnderDevelopment) {
this._extHostLogService.warn(`[Deprecation Warning] '${apiId}' is deprecated. ${migrationSuggestion}`);
}
type DeprecationTelemetry = {
extensionId: string;
apiId: string;
};
type DeprecationTelemetryMeta = {
extensionId: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
apiId: { classification: 'SystemMetaData', purpose: 'PerformanceAndHealth' };
};
this._telemetryShape.$publicLog2<DeprecationTelemetry, DeprecationTelemetryMeta>('extHostDeprecatedApiUsage', {
extensionId: extension.identifier.value,
apiId: apiId,
});
}
private getUsageKey(apiId: string, extension: IExtensionDescription): string {
return `${apiId}-${extension.identifier.value}`;
}
}
export const NullApiDeprecationService = Object.freeze(new class implements IExtHostApiDeprecationService {
_serviceBrand: undefined;
public report(_apiId: string, _extension: IExtensionDescription, _warningMessage: string): void {
// noop
}
}());