Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/extensions/browser/exeBasedRecommendations.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 { IExtensionTipsService, IExecutableBasedExtensionTip } from '../../../../platform/extensionManagement/common/extensionManagement.js';
7
import { ExtensionRecommendations, ExtensionRecommendation } from './extensionRecommendations.js';
8
import { localize } from '../../../../nls.js';
9
import { ExtensionRecommendationReason } from '../../../services/extensionRecommendations/common/extensionRecommendations.js';
10
11
export class ExeBasedRecommendations extends ExtensionRecommendations {
12
13
private _otherTips: IExecutableBasedExtensionTip[] = [];
14
private _importantTips: IExecutableBasedExtensionTip[] = [];
15
16
get otherRecommendations(): ReadonlyArray<ExtensionRecommendation> { return this._otherTips.map(tip => this.toExtensionRecommendation(tip)); }
17
get importantRecommendations(): ReadonlyArray<ExtensionRecommendation> { return this._importantTips.map(tip => this.toExtensionRecommendation(tip)); }
18
19
get recommendations(): ReadonlyArray<ExtensionRecommendation> { return [...this.importantRecommendations, ...this.otherRecommendations]; }
20
21
constructor(
22
@IExtensionTipsService private readonly extensionTipsService: IExtensionTipsService,
23
) {
24
super();
25
}
26
27
getRecommendations(exe: string): { important: ExtensionRecommendation[]; others: ExtensionRecommendation[] } {
28
const important = this._importantTips
29
.filter(tip => tip.exeName.toLowerCase() === exe.toLowerCase())
30
.map(tip => this.toExtensionRecommendation(tip));
31
32
const others = this._otherTips
33
.filter(tip => tip.exeName.toLowerCase() === exe.toLowerCase())
34
.map(tip => this.toExtensionRecommendation(tip));
35
36
return { important, others };
37
}
38
39
protected async doActivate(): Promise<void> {
40
this._otherTips = await this.extensionTipsService.getOtherExecutableBasedTips();
41
await this.fetchImportantExeBasedRecommendations();
42
}
43
44
private _importantExeBasedRecommendations: Promise<Map<string, IExecutableBasedExtensionTip>> | undefined;
45
private async fetchImportantExeBasedRecommendations(): Promise<Map<string, IExecutableBasedExtensionTip>> {
46
if (!this._importantExeBasedRecommendations) {
47
this._importantExeBasedRecommendations = this.doFetchImportantExeBasedRecommendations();
48
}
49
return this._importantExeBasedRecommendations;
50
}
51
52
private async doFetchImportantExeBasedRecommendations(): Promise<Map<string, IExecutableBasedExtensionTip>> {
53
const importantExeBasedRecommendations = new Map<string, IExecutableBasedExtensionTip>();
54
this._importantTips = await this.extensionTipsService.getImportantExecutableBasedTips();
55
this._importantTips.forEach(tip => importantExeBasedRecommendations.set(tip.extensionId.toLowerCase(), tip));
56
return importantExeBasedRecommendations;
57
}
58
59
private toExtensionRecommendation(tip: IExecutableBasedExtensionTip): ExtensionRecommendation {
60
return {
61
extension: tip.extensionId.toLowerCase(),
62
reason: {
63
reasonId: ExtensionRecommendationReason.Executable,
64
reasonText: localize('exeBasedRecommendation', "This extension is recommended because you have {0} installed.", tip.exeFriendlyName)
65
}
66
};
67
}
68
69
}
70
71
72