Skip to content

Commit 8678f8b

Browse files
committed
Trim recommendations #36649
1 parent 80f61a8 commit 8678f8b

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

src/vs/platform/extensionManagement/common/extensionManagement.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ export const IExtensionTipsService = createDecorator<IExtensionTipsService>('ext
305305

306306
export interface IExtensionTipsService {
307307
_serviceBrand: any;
308-
getRecommendations(installedExtensions: string[], searchText: string): string[];
308+
getFileBasedRecommendations(): string[];
309+
getOtherRecommendations(): string[];
309310
getWorkspaceRecommendations(): TPromise<string[]>;
310311
getKeymapRecommendations(): string[];
311312
getKeywordsForExtension(extension: string): string[];

src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts

+8-29
Original file line numberDiff line numberDiff line change
@@ -124,42 +124,21 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe
124124
}
125125
}
126126

127-
getRecommendations(installedExtensions: string[], searchText: string): string[] {
127+
getFileBasedRecommendations(): string[] {
128128
const fileBased = Object.keys(this._fileBasedRecommendations)
129-
.filter(recommendation => {
130-
return installedExtensions.indexOf(recommendation) === -1
131-
&& recommendation.toLowerCase().indexOf(searchText) > -1;
132-
}).sort((a, b) => {
129+
.sort((a, b) => {
133130
return this._fileBasedRecommendations[a] > this._fileBasedRecommendations[b] ? -1 : 1;
134131
});
132+
return fileBased;
133+
}
135134

136-
const exeBased = this._exeBasedRecommendations
137-
.filter((recommendation, index) => {
138-
return this._exeBasedRecommendations.indexOf(recommendation) === index
139-
&& installedExtensions.indexOf(recommendation) === -1
140-
&& fileBased.indexOf(recommendation) === -1
141-
&& recommendation.toLowerCase().indexOf(searchText) > -1;
142-
});
143-
144-
// Sort recommendations such that few of the exeBased ones show up earliar
145-
const x = Math.min(6, fileBased.length);
146-
const y = Math.min(4, exeBased.length);
147-
const sortedRecommendations = fileBased.slice(0, x);
148-
sortedRecommendations.push(...exeBased.slice(0, y));
149-
sortedRecommendations.push(...fileBased.slice(x));
150-
sortedRecommendations.push(...exeBased.slice(y));
151-
152-
/* __GDPR__
153-
"extensionRecommendations:unfiltered" : {
154-
"fileBased" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
155-
"exeBased": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
156-
}
157-
*/
158-
this.telemetryService.publicLog('extensionRecommendations:unfiltered', { fileBased, exeBased });
135+
getOtherRecommendations(): string[] {
159136

160-
return sortedRecommendations;
137+
return distinct(this._exeBasedRecommendations);
161138
}
162139

140+
141+
163142
getKeymapRecommendations(): string[] {
164143
return product.keymapExtensionTips || [];
165144
}

src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts

+40-17
Original file line numberDiff line numberDiff line change
@@ -293,23 +293,12 @@ export class ExtensionsListView extends ViewsViewletPanel {
293293
.then(result => result.filter(e => e.type === LocalExtensionType.User))
294294
.then(local => {
295295
const installedExtensions = local.map(x => `${x.publisher}.${x.name}`);
296-
return TPromise.join([TPromise.as(this.tipsService.getRecommendations(installedExtensions, value)), this.tipsService.getWorkspaceRecommendations()])
297-
.then(([recommendations, workspaceRecommendations]) => {
298-
299-
workspaceRecommendations = workspaceRecommendations
300-
.filter(name => {
301-
return recommendations.indexOf(name) === -1
302-
&& installedExtensions.indexOf(name) === -1
303-
&& name.toLowerCase().indexOf(value) > -1;
304-
});
296+
let fileBasedRecommendations = this.tipsService.getFileBasedRecommendations();
297+
let others = this.tipsService.getOtherRecommendations();
305298

306-
// Sort recommendations such that few of the workspace ones show up earliar
307-
const x = Math.min(4, recommendations.length);
308-
const y = Math.min(4, workspaceRecommendations.length);
309-
const names = recommendations.slice(0, x);
310-
names.push(...workspaceRecommendations.slice(0, y));
311-
names.push(...recommendations.slice(x));
312-
names.push(...workspaceRecommendations.slice(y));
299+
return this.tipsService.getWorkspaceRecommendations()
300+
.then(workspaceRecommendations => {
301+
const names = this.getTrimmedRecommendations(installedExtensions, value, fileBasedRecommendations, others, workspaceRecommendations);
313302

314303
this.telemetryService.publicLog('extensionAllRecommendations:open', { count: names.length });
315304
if (!names.length) {
@@ -331,7 +320,12 @@ export class ExtensionsListView extends ViewsViewletPanel {
331320
return this.extensionsWorkbenchService.queryLocal()
332321
.then(result => result.filter(e => e.type === LocalExtensionType.User))
333322
.then(local => {
334-
const names = this.tipsService.getRecommendations(local.map(x => `${x.publisher}.${x.name}`), value);
323+
let fileBasedRecommendations = this.tipsService.getFileBasedRecommendations();
324+
let others = this.tipsService.getOtherRecommendations();
325+
326+
const installedExtensions = local.map(x => `${x.publisher}.${x.name}`);
327+
328+
const names = this.getTrimmedRecommendations(installedExtensions, value, fileBasedRecommendations, others, []);
335329

336330
/* __GDPR__
337331
"extensionRecommendations:open" : {
@@ -352,6 +346,35 @@ export class ExtensionsListView extends ViewsViewletPanel {
352346
});
353347
}
354348

349+
// Given all recommendations, trims and returns recommendations in the relevant order after filtering out installed extensions
350+
private getTrimmedRecommendations(installedExtensions: string[], value: string, fileBasedRecommendations: string[], otherRecommendations: string[], workpsaceRecommendations: string[], ) {
351+
const totalCount = 8;
352+
workpsaceRecommendations = workpsaceRecommendations
353+
.filter(name => {
354+
return installedExtensions.indexOf(name) === -1
355+
&& name.toLowerCase().indexOf(value) > -1;
356+
});
357+
fileBasedRecommendations = fileBasedRecommendations.filter(x => {
358+
return installedExtensions.indexOf(x) === -1
359+
&& workpsaceRecommendations.indexOf(x) === -1
360+
&& x.toLowerCase().indexOf(value) > -1;
361+
});
362+
otherRecommendations = otherRecommendations.filter(x => {
363+
return installedExtensions.indexOf(x) === -1
364+
&& fileBasedRecommendations.indexOf(x) === -1
365+
&& workpsaceRecommendations.indexOf(x) === -1
366+
&& x.toLowerCase().indexOf(value) > -1;
367+
});
368+
369+
let otherCount = Math.min(2, otherRecommendations.length);
370+
let fileBasedCount = Math.min(fileBasedRecommendations.length, totalCount - workpsaceRecommendations.length - otherCount);
371+
let names = workpsaceRecommendations;
372+
names.push(...fileBasedRecommendations.splice(0, fileBasedCount));
373+
names.push(...otherRecommendations.splice(0, otherCount));
374+
375+
return names;
376+
}
377+
355378
private getWorkspaceRecommendationsModel(query: Query, options: IQueryOptions): TPromise<IPagedModel<IExtension>> {
356379
const value = query.value.replace(/@recommended:workspace/g, '').trim().toLowerCase();
357380
return this.tipsService.getWorkspaceRecommendations()

0 commit comments

Comments
 (0)