From 8678f8b07a9340d36dd899cbff901230ac8cbde0 Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Tue, 24 Oct 2017 15:53:16 -0700 Subject: [PATCH] Trim recommendations #36649 --- .../common/extensionManagement.ts | 3 +- .../electron-browser/extensionTipsService.ts | 41 ++++--------- .../electron-browser/extensionsViews.ts | 57 +++++++++++++------ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/vs/platform/extensionManagement/common/extensionManagement.ts b/src/vs/platform/extensionManagement/common/extensionManagement.ts index 669d4bab78e..f9a67aeb8dd 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagement.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagement.ts @@ -305,7 +305,8 @@ export const IExtensionTipsService = createDecorator('ext export interface IExtensionTipsService { _serviceBrand: any; - getRecommendations(installedExtensions: string[], searchText: string): string[]; + getFileBasedRecommendations(): string[]; + getOtherRecommendations(): string[]; getWorkspaceRecommendations(): TPromise; getKeymapRecommendations(): string[]; getKeywordsForExtension(extension: string): string[]; diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts b/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts index 68fa87d822c..fc88fb2ee0d 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts @@ -124,42 +124,21 @@ export class ExtensionTipsService extends Disposable implements IExtensionTipsSe } } - getRecommendations(installedExtensions: string[], searchText: string): string[] { + getFileBasedRecommendations(): string[] { const fileBased = Object.keys(this._fileBasedRecommendations) - .filter(recommendation => { - return installedExtensions.indexOf(recommendation) === -1 - && recommendation.toLowerCase().indexOf(searchText) > -1; - }).sort((a, b) => { + .sort((a, b) => { return this._fileBasedRecommendations[a] > this._fileBasedRecommendations[b] ? -1 : 1; }); - - const exeBased = this._exeBasedRecommendations - .filter((recommendation, index) => { - return this._exeBasedRecommendations.indexOf(recommendation) === index - && installedExtensions.indexOf(recommendation) === -1 - && fileBased.indexOf(recommendation) === -1 - && recommendation.toLowerCase().indexOf(searchText) > -1; - }); - - // Sort recommendations such that few of the exeBased ones show up earliar - const x = Math.min(6, fileBased.length); - const y = Math.min(4, exeBased.length); - const sortedRecommendations = fileBased.slice(0, x); - sortedRecommendations.push(...exeBased.slice(0, y)); - sortedRecommendations.push(...fileBased.slice(x)); - sortedRecommendations.push(...exeBased.slice(y)); - - /* __GDPR__ - "extensionRecommendations:unfiltered" : { - "fileBased" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, - "exeBased": { "classification": "SystemMetaData", "purpose": "FeatureInsight" } - } - */ - this.telemetryService.publicLog('extensionRecommendations:unfiltered', { fileBased, exeBased }); - - return sortedRecommendations; + return fileBased; } + getOtherRecommendations(): string[] { + + return distinct(this._exeBasedRecommendations); + } + + + getKeymapRecommendations(): string[] { return product.keymapExtensionTips || []; } diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts b/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts index 8b2c2030c5f..c3be19fb73a 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensionsViews.ts @@ -293,23 +293,12 @@ export class ExtensionsListView extends ViewsViewletPanel { .then(result => result.filter(e => e.type === LocalExtensionType.User)) .then(local => { const installedExtensions = local.map(x => `${x.publisher}.${x.name}`); - return TPromise.join([TPromise.as(this.tipsService.getRecommendations(installedExtensions, value)), this.tipsService.getWorkspaceRecommendations()]) - .then(([recommendations, workspaceRecommendations]) => { + let fileBasedRecommendations = this.tipsService.getFileBasedRecommendations(); + let others = this.tipsService.getOtherRecommendations(); - workspaceRecommendations = workspaceRecommendations - .filter(name => { - return recommendations.indexOf(name) === -1 - && installedExtensions.indexOf(name) === -1 - && name.toLowerCase().indexOf(value) > -1; - }); - - // Sort recommendations such that few of the workspace ones show up earliar - const x = Math.min(4, recommendations.length); - const y = Math.min(4, workspaceRecommendations.length); - const names = recommendations.slice(0, x); - names.push(...workspaceRecommendations.slice(0, y)); - names.push(...recommendations.slice(x)); - names.push(...workspaceRecommendations.slice(y)); + return this.tipsService.getWorkspaceRecommendations() + .then(workspaceRecommendations => { + const names = this.getTrimmedRecommendations(installedExtensions, value, fileBasedRecommendations, others, workspaceRecommendations); this.telemetryService.publicLog('extensionAllRecommendations:open', { count: names.length }); if (!names.length) { @@ -331,7 +320,12 @@ export class ExtensionsListView extends ViewsViewletPanel { return this.extensionsWorkbenchService.queryLocal() .then(result => result.filter(e => e.type === LocalExtensionType.User)) .then(local => { - const names = this.tipsService.getRecommendations(local.map(x => `${x.publisher}.${x.name}`), value); + let fileBasedRecommendations = this.tipsService.getFileBasedRecommendations(); + let others = this.tipsService.getOtherRecommendations(); + + const installedExtensions = local.map(x => `${x.publisher}.${x.name}`); + + const names = this.getTrimmedRecommendations(installedExtensions, value, fileBasedRecommendations, others, []); /* __GDPR__ "extensionRecommendations:open" : { @@ -352,6 +346,35 @@ export class ExtensionsListView extends ViewsViewletPanel { }); } + // Given all recommendations, trims and returns recommendations in the relevant order after filtering out installed extensions + private getTrimmedRecommendations(installedExtensions: string[], value: string, fileBasedRecommendations: string[], otherRecommendations: string[], workpsaceRecommendations: string[], ) { + const totalCount = 8; + workpsaceRecommendations = workpsaceRecommendations + .filter(name => { + return installedExtensions.indexOf(name) === -1 + && name.toLowerCase().indexOf(value) > -1; + }); + fileBasedRecommendations = fileBasedRecommendations.filter(x => { + return installedExtensions.indexOf(x) === -1 + && workpsaceRecommendations.indexOf(x) === -1 + && x.toLowerCase().indexOf(value) > -1; + }); + otherRecommendations = otherRecommendations.filter(x => { + return installedExtensions.indexOf(x) === -1 + && fileBasedRecommendations.indexOf(x) === -1 + && workpsaceRecommendations.indexOf(x) === -1 + && x.toLowerCase().indexOf(value) > -1; + }); + + let otherCount = Math.min(2, otherRecommendations.length); + let fileBasedCount = Math.min(fileBasedRecommendations.length, totalCount - workpsaceRecommendations.length - otherCount); + let names = workpsaceRecommendations; + names.push(...fileBasedRecommendations.splice(0, fileBasedCount)); + names.push(...otherRecommendations.splice(0, otherCount)); + + return names; + } + private getWorkspaceRecommendationsModel(query: Query, options: IQueryOptions): TPromise> { const value = query.value.replace(/@recommended:workspace/g, '').trim().toLowerCase(); return this.tipsService.getWorkspaceRecommendations()