Trim recommendations #36649

This commit is contained in:
Ramya Achutha Rao
2017-10-24 15:53:16 -07:00
parent 80f61a8a49
commit 8678f8b07a
3 changed files with 52 additions and 49 deletions

View File

@@ -305,7 +305,8 @@ export const IExtensionTipsService = createDecorator<IExtensionTipsService>('ext
export interface IExtensionTipsService {
_serviceBrand: any;
getRecommendations(installedExtensions: string[], searchText: string): string[];
getFileBasedRecommendations(): string[];
getOtherRecommendations(): string[];
getWorkspaceRecommendations(): TPromise<string[]>;
getKeymapRecommendations(): string[];
getKeywordsForExtension(extension: string): string[];

View File

@@ -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 || [];
}

View File

@@ -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<IPagedModel<IExtension>> {
const value = query.value.replace(/@recommended:workspace/g, '').trim().toLowerCase();
return this.tipsService.getWorkspaceRecommendations()