@@ -293,23 +293,12 @@ export class ExtensionsListView extends ViewsViewletPanel {
293
293
. then ( result => result . filter ( e => e . type === LocalExtensionType . User ) )
294
294
. then ( local => {
295
295
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 ( ) ;
305
298
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 ) ;
313
302
314
303
this . telemetryService . publicLog ( 'extensionAllRecommendations:open' , { count : names . length } ) ;
315
304
if ( ! names . length ) {
@@ -331,7 +320,12 @@ export class ExtensionsListView extends ViewsViewletPanel {
331
320
return this . extensionsWorkbenchService . queryLocal ( )
332
321
. then ( result => result . filter ( e => e . type === LocalExtensionType . User ) )
333
322
. 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 , [ ] ) ;
335
329
336
330
/* __GDPR__
337
331
"extensionRecommendations:open" : {
@@ -352,6 +346,35 @@ export class ExtensionsListView extends ViewsViewletPanel {
352
346
} ) ;
353
347
}
354
348
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
+
355
378
private getWorkspaceRecommendationsModel ( query : Query , options : IQueryOptions ) : TPromise < IPagedModel < IExtension > > {
356
379
const value = query . value . replace ( / @ r e c o m m e n d e d : w o r k s p a c e / g, '' ) . trim ( ) . toLowerCase ( ) ;
357
380
return this . tipsService . getWorkspaceRecommendations ( )
0 commit comments