@@ -16,6 +16,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
1616import EventOf , { mapEvent , filterEvent } from 'vs/base/common/event' ;
1717import { IAction } from 'vs/base/common/actions' ;
1818import { domEvent } from 'vs/base/browser/event' ;
19+ import { Separator } from 'vs/base/browser/ui/actionbar/actionbar' ;
1920import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
2021import { KeyCode } from 'vs/base/common/keyCodes' ;
2122import { Viewlet } from 'vs/workbench/browser/viewlet' ;
@@ -26,9 +27,10 @@ import { PagedList } from 'vs/base/browser/ui/list/listPaging';
2627import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
2728import { Delegate , Renderer } from './extensionsList' ;
2829import { IExtensionsWorkbenchService , IExtension , IExtensionsViewlet , VIEWLET_ID } from './extensions' ;
29- import { ShowRecommendedExtensionsAction , ShowPopularExtensionsAction , ShowInstalledExtensionsAction , ShowOutdatedExtensionsAction , ClearExtensionsInputAction } from './extensionsActions' ;
30+ import { ShowRecommendedExtensionsAction , ShowPopularExtensionsAction , ShowInstalledExtensionsAction , ShowOutdatedExtensionsAction , ClearExtensionsInputAction , ChangeSortAction } from './extensionsActions' ;
3031import { IExtensionManagementService , IExtensionGalleryService , IExtensionTipsService , SortBy , SortOrder , IQueryOptions } from 'vs/platform/extensionManagement/common/extensionManagement' ;
3132import { ExtensionsInput } from './extensionsInput' ;
33+ import { Query } from './extensionQuery' ;
3234import { IProgressService } from 'vs/platform/progress/common/progress' ;
3335import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService' ;
3436import { IURLService } from 'vs/platform/url/common/url' ;
@@ -154,7 +156,12 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
154156 this . instantiationService . createInstance ( ShowInstalledExtensionsAction , ShowInstalledExtensionsAction . ID , ShowInstalledExtensionsAction . LABEL ) ,
155157 this . instantiationService . createInstance ( ShowOutdatedExtensionsAction , ShowOutdatedExtensionsAction . ID , ShowOutdatedExtensionsAction . LABEL ) ,
156158 this . instantiationService . createInstance ( ShowRecommendedExtensionsAction , ShowRecommendedExtensionsAction . ID , ShowRecommendedExtensionsAction . LABEL ) ,
157- this . instantiationService . createInstance ( ShowPopularExtensionsAction , ShowPopularExtensionsAction . ID , ShowPopularExtensionsAction . LABEL )
159+ this . instantiationService . createInstance ( ShowPopularExtensionsAction , ShowPopularExtensionsAction . ID , ShowPopularExtensionsAction . LABEL ) ,
160+ new Separator ( ) ,
161+ this . instantiationService . createInstance ( ChangeSortAction , 'extensions.sort.install.asc' , localize ( 'sort by installs' , "Sort By: Install Count" ) , this . onSearchChange , 'installs' , undefined ) ,
162+ new Separator ( ) ,
163+ this . instantiationService . createInstance ( ChangeSortAction , 'extensions.sort.asc' , localize ( 'ascending' , "Sort Order: ↑" ) , this . onSearchChange , undefined , 'asc' ) ,
164+ this . instantiationService . createInstance ( ChangeSortAction , 'extensions.sort.desc' , localize ( 'descending' , "Sort Order: ↓" ) , this . onSearchChange , undefined , 'desc' ) ,
158165 ] ;
159166 }
160167
@@ -196,10 +203,11 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
196203 return local . then ( result => new PagedModel ( result ) ) ;
197204 }
198205
206+ const query = Query . parse ( value ) ;
199207 let options : IQueryOptions = { } ;
200208
201- if ( / @ r e c o m m e n d e d / i. test ( value ) ) {
202- value = value . replace ( / @ r e c o m m e n d e d / g, '' ) . trim ( ) ;
209+ if ( / @ r e c o m m e n d e d / i. test ( query . value ) ) {
210+ const value = query . value . replace ( / @ r e c o m m e n d e d / g, '' ) . trim ( ) ;
203211
204212 return this . extensionsWorkbenchService . queryLocal ( ) . then ( local => {
205213 const names = this . tipsService . getRecommendations ( )
@@ -215,29 +223,17 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
215223 } ) ;
216224 }
217225
218- value = value . replace ( / @ s o r t : ( \w + ) ( - a s c | - d e s c ) ? \b / g, ( match , by , order ) => {
219- let sortOrder = SortOrder . Default ;
220-
221- switch ( order ) {
222- case '-asc' : sortOrder = SortOrder . Ascending ; break ;
223- case '-desc' : sortOrder = SortOrder . Descending ; break ;
224- }
225-
226- let sortBy = SortBy . NoneOrRelevance ;
227-
228- switch ( by ) {
229- case 'installs' : sortBy = SortBy . InstallCount ; break ;
230- default : return match ;
231- }
232-
233- options = assign ( options , { sortBy, sortOrder } ) ;
234- return '' ;
235- } ) ;
226+ switch ( query . sortBy ) {
227+ case 'installs' : options = assign ( options , { sortBy : SortBy . InstallCount } ) ; break ;
228+ }
236229
237- value = value . trim ( ) ;
230+ switch ( query . sortOrder ) {
231+ case 'asc' : options = assign ( options , { sortOrder : SortOrder . Ascending } ) ; break ;
232+ case 'desc' : options = assign ( options , { sortOrder : SortOrder . Descending } ) ; break ;
233+ }
238234
239- if ( value ) {
240- options = assign ( options , { text : value } ) ;
235+ if ( query . value ) {
236+ options = assign ( options , { text : query . value } ) ;
241237 }
242238
243239 return this . extensionsWorkbenchService . queryGallery ( options )
0 commit comments