Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/common/extHostApiDeprecationService.ts
3296 views
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 { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
7
import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
8
import { ILogService } from '../../../platform/log/common/log.js';
9
import * as extHostProtocol from './extHost.protocol.js';
10
import { IExtHostRpcService } from './extHostRpcService.js';
11
12
export interface IExtHostApiDeprecationService {
13
readonly _serviceBrand: undefined;
14
15
report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void;
16
}
17
18
export const IExtHostApiDeprecationService = createDecorator<IExtHostApiDeprecationService>('IExtHostApiDeprecationService');
19
20
export class ExtHostApiDeprecationService implements IExtHostApiDeprecationService {
21
22
declare readonly _serviceBrand: undefined;
23
24
private readonly _reportedUsages = new Set<string>();
25
private readonly _telemetryShape: extHostProtocol.MainThreadTelemetryShape;
26
27
constructor(
28
@IExtHostRpcService rpc: IExtHostRpcService,
29
@ILogService private readonly _extHostLogService: ILogService,
30
) {
31
this._telemetryShape = rpc.getProxy(extHostProtocol.MainContext.MainThreadTelemetry);
32
}
33
34
public report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string): void {
35
const key = this.getUsageKey(apiId, extension);
36
if (this._reportedUsages.has(key)) {
37
return;
38
}
39
this._reportedUsages.add(key);
40
41
if (extension.isUnderDevelopment) {
42
this._extHostLogService.warn(`[Deprecation Warning] '${apiId}' is deprecated. ${migrationSuggestion}`);
43
}
44
45
type DeprecationTelemetry = {
46
extensionId: string;
47
apiId: string;
48
};
49
type DeprecationTelemetryMeta = {
50
extensionId: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The id of the extension that is using the deprecated API' };
51
apiId: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The id of the deprecated API' };
52
owner: 'mjbvz';
53
comment: 'Helps us gain insights on extensions using deprecated API so we can assist in migration to new API';
54
};
55
this._telemetryShape.$publicLog2<DeprecationTelemetry, DeprecationTelemetryMeta>('extHostDeprecatedApiUsage', {
56
extensionId: extension.identifier.value,
57
apiId: apiId,
58
});
59
}
60
61
private getUsageKey(apiId: string, extension: IExtensionDescription): string {
62
return `${apiId}-${extension.identifier.value}`;
63
}
64
}
65
66
67
export const NullApiDeprecationService = Object.freeze(new class implements IExtHostApiDeprecationService {
68
declare readonly _serviceBrand: undefined;
69
70
public report(_apiId: string, _extension: IExtensionDescription, _warningMessage: string): void {
71
// noop
72
}
73
}());
74
75