From 479d4e6e41796e31aa7d361c26b90297713defaa Mon Sep 17 00:00:00 2001 From: Robert Jin Date: Fri, 13 Dec 2019 23:26:26 +0000 Subject: [PATCH] Add string descriptions to SearchSortOrder enum --- .../search/browser/search.contribution.ts | 6 +++--- .../contrib/search/browser/searchView.ts | 16 ++++++++-------- .../contrib/search/common/searchModel.ts | 14 +++++++------- .../search/test/browser/searchViewlet.test.ts | 6 +++--- .../workbench/services/search/common/search.ts | 16 ++++++++-------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/vs/workbench/contrib/search/browser/search.contribution.ts b/src/vs/workbench/contrib/search/browser/search.contribution.ts index 1f62e26c981..7ec30f5e733 100644 --- a/src/vs/workbench/contrib/search/browser/search.contribution.ts +++ b/src/vs/workbench/contrib/search/browser/search.contribution.ts @@ -51,7 +51,7 @@ import { ISearchHistoryService, SearchHistoryService } from 'vs/workbench/contri import { FileMatchOrMatch, ISearchWorkbenchService, RenderableMatch, SearchWorkbenchService, FileMatch, Match, FolderMatch } from 'vs/workbench/contrib/search/common/searchModel'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; -import { ISearchConfiguration, ISearchConfigurationProperties, PANEL_ID, VIEWLET_ID, VIEW_ID, VIEW_CONTAINER, SearchSortOrderConfiguration } from 'vs/workbench/services/search/common/search'; +import { ISearchConfiguration, ISearchConfigurationProperties, PANEL_ID, VIEWLET_ID, VIEW_ID, VIEW_CONTAINER, SearchSortOrder } from 'vs/workbench/services/search/common/search'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { ExplorerViewPaneContainer } from 'vs/workbench/contrib/files/browser/explorerViewlet'; @@ -829,8 +829,8 @@ configurationRegistry.registerConfiguration({ }, 'search.sortOrder': { 'type': 'string', - 'enum': [SearchSortOrderConfiguration.default, SearchSortOrderConfiguration.fileNames, SearchSortOrderConfiguration.type, SearchSortOrderConfiguration.modified, SearchSortOrderConfiguration.countDescending, SearchSortOrderConfiguration.countAscending], - 'default': SearchSortOrderConfiguration.default, + 'enum': [SearchSortOrder.Default, SearchSortOrder.FileNames, SearchSortOrder.Type, SearchSortOrder.Modified, SearchSortOrder.CountDescending, SearchSortOrder.CountAscending], + 'default': SearchSortOrder.Default, 'enumDescriptions': [ nls.localize('searchSortOrder.default', 'Results are sorted by folder and file names, in alphabetical order.'), nls.localize('searchSortOrder.filesOnly', 'Results are sorted by file names ignoring folder order, in alphabetical order.'), diff --git a/src/vs/workbench/contrib/search/browser/searchView.ts b/src/vs/workbench/contrib/search/browser/searchView.ts index dc9c622f323..931d8e286e4 100644 --- a/src/vs/workbench/contrib/search/browser/searchView.ts +++ b/src/vs/workbench/contrib/search/browser/searchView.ts @@ -34,7 +34,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { TreeResourceNavigator2, WorkbenchObjectTree, getSelectionKeyboardEvent } from 'vs/platform/list/browser/listService'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IProgressService, IProgressStep, IProgress } from 'vs/platform/progress/common/progress'; -import { IPatternInfo, ISearchComplete, ISearchConfiguration, ISearchConfigurationProperties, ITextQuery, VIEW_ID, VIEWLET_ID, SearchSortOrderConfiguration } from 'vs/workbench/services/search/common/search'; +import { IPatternInfo, ISearchComplete, ISearchConfiguration, ISearchConfigurationProperties, ITextQuery, VIEW_ID, VIEWLET_ID, SearchSortOrder } from 'vs/workbench/services/search/common/search'; import { ISearchHistoryService, ISearchHistoryValues } from 'vs/workbench/contrib/search/common/searchHistoryService'; import { diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, editorFindMatchHighlight, editorFindMatchHighlightBorder, listActiveSelectionForeground, foreground } from 'vs/platform/theme/common/colorRegistry'; import { ICssStyleCollector, ITheme, IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; @@ -196,7 +196,7 @@ export class SearchView extends ViewPane { }); this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration('search.sortOrder')) { - if (this.searchConfig.sortOrder === SearchSortOrderConfiguration.modified) { + if (this.searchConfig.sortOrder === SearchSortOrder.Modified) { // If changing away from modified, remove all fileStats // so that updated files are re-retrieved next time. this.removeFileStats(); @@ -505,7 +505,7 @@ export class SearchView extends ViewPane { const collapseResults = this.searchConfig.collapseResults; if (!event || event.added || event.removed) { // Refresh whole tree - if (this.searchConfig.sortOrder === SearchSortOrderConfiguration.modified) { + if (this.searchConfig.sortOrder === SearchSortOrder.Modified) { // Ensure all matches have retrieved their file stat this.retrieveFileStats() .then(() => this.tree.setChildren(null, this.createResultIterator(collapseResults))); @@ -514,8 +514,8 @@ export class SearchView extends ViewPane { } } else { // If updated counts affect our search order, re-sort the view. - if (this.searchConfig.sortOrder === SearchSortOrderConfiguration.countAscending || - this.searchConfig.sortOrder === SearchSortOrderConfiguration.countDescending) { + if (this.searchConfig.sortOrder === SearchSortOrder.CountAscending || + this.searchConfig.sortOrder === SearchSortOrder.CountDescending) { this.tree.setChildren(null, this.createResultIterator(collapseResults)); } else { // FileMatch modified, refresh those elements @@ -1715,7 +1715,7 @@ export class SearchView extends ViewPane { } private onFilesChanged(e: FileChangesEvent): void { - if (!this.viewModel || (this.searchConfig.sortOrder !== SearchSortOrderConfiguration.modified && !e.gotDeleted())) { + if (!this.viewModel || (this.searchConfig.sortOrder !== SearchSortOrder.Modified && !e.gotDeleted())) { return; } @@ -1727,7 +1727,7 @@ export class SearchView extends ViewPane { } else { // Check if the changed file contained matches const changedMatches = matches.filter(m => e.contains(m.resource)); - if (changedMatches.length && this.searchConfig.sortOrder === SearchSortOrderConfiguration.modified) { + if (changedMatches.length && this.searchConfig.sortOrder === SearchSortOrder.Modified) { // No matches need to be removed, but modified files need to have their file stat updated. this.updateFileStats(changedMatches).then(() => this.refreshTree()); } @@ -1809,7 +1809,7 @@ export class SearchView extends ViewPane { } private async updateFileStats(elements: FileMatch[]): Promise { - const files = this.searchResult.matches().map(f => f.resolveFileStat(this.fileService)); + const files = elements.map(f => f.resolveFileStat(this.fileService)); await Promise.all(files); } diff --git a/src/vs/workbench/contrib/search/common/searchModel.ts b/src/vs/workbench/contrib/search/common/searchModel.ts index 73d0518940a..714140379bd 100644 --- a/src/vs/workbench/contrib/search/common/searchModel.ts +++ b/src/vs/workbench/contrib/search/common/searchModel.ts @@ -20,7 +20,7 @@ import { IModelService } from 'vs/editor/common/services/modelService'; import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IProgress, IProgressStep } from 'vs/platform/progress/common/progress'; import { ReplacePattern } from 'vs/workbench/services/search/common/replace'; -import { IFileMatch, IPatternInfo, ISearchComplete, ISearchProgressItem, ISearchConfigurationProperties, ISearchService, ITextQuery, ITextSearchPreviewOptions, ITextSearchMatch, ITextSearchStats, resultIsMatch, ISearchRange, OneLineRange, ITextSearchContext, ITextSearchResult, SearchSortOrderConfiguration } from 'vs/workbench/services/search/common/search'; +import { IFileMatch, IPatternInfo, ISearchComplete, ISearchProgressItem, ISearchConfigurationProperties, ISearchService, ITextQuery, ITextSearchPreviewOptions, ITextSearchMatch, ITextSearchStats, resultIsMatch, ISearchRange, OneLineRange, ITextSearchContext, ITextSearchResult, SearchSortOrder } from 'vs/workbench/services/search/common/search'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { overviewRulerFindMatchForeground, minimapFindMatch } from 'vs/platform/theme/common/colorRegistry'; import { themeColorFromId } from 'vs/platform/theme/common/themeService'; @@ -643,22 +643,22 @@ export class FolderMatchWithResource extends FolderMatch { * Compares instances of the same match type. Different match types should not be siblings * and their sort order is undefined. */ -export function searchMatchComparer(elementA: RenderableMatch, elementB: RenderableMatch, sortOrder: SearchSortOrderConfiguration = SearchSortOrderConfiguration.default): number { +export function searchMatchComparer(elementA: RenderableMatch, elementB: RenderableMatch, sortOrder: SearchSortOrder = SearchSortOrder.Default): number { if (elementA instanceof FolderMatch && elementB instanceof FolderMatch) { return elementA.index() - elementB.index(); } if (elementA instanceof FileMatch && elementB instanceof FileMatch) { switch (sortOrder) { - case SearchSortOrderConfiguration.countDescending: + case SearchSortOrder.CountDescending: return elementB.count() - elementA.count(); - case SearchSortOrderConfiguration.countAscending: + case SearchSortOrder.CountAscending: return elementA.count() - elementB.count(); - case SearchSortOrderConfiguration.type: + case SearchSortOrder.Type: return compareFileExtensions(elementA.name(), elementB.name()); - case SearchSortOrderConfiguration.fileNames: + case SearchSortOrder.FileNames: return compareFileNames(elementA.name(), elementB.name()); - case SearchSortOrderConfiguration.modified: + case SearchSortOrder.Modified: const fileStatA = elementA.fileStat; const fileStatB = elementB.fileStat; if (fileStatA && fileStatB) { diff --git a/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts b/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts index 570b8408b03..7c1ea08b6e3 100644 --- a/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts +++ b/src/vs/workbench/contrib/search/test/browser/searchViewlet.test.ts @@ -9,7 +9,7 @@ import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; -import { IFileMatch, ITextSearchMatch, OneLineRange, QueryType, SearchSortOrderConfiguration } from 'vs/workbench/services/search/common/search'; +import { IFileMatch, ITextSearchMatch, OneLineRange, QueryType, SearchSortOrder } from 'vs/workbench/services/search/common/search'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; import { FileMatch, Match, searchMatchComparer, SearchResult } from 'vs/workbench/contrib/search/common/searchModel'; @@ -90,9 +90,9 @@ suite('Search - Viewlet', () => { // By default, path < path2 assert(searchMatchComparer(fileMatch1, fileMatch2) < 0); // By filenames, foo10 > foo1 - assert(searchMatchComparer(fileMatch1, fileMatch2, SearchSortOrderConfiguration.fileNames) > 0); + assert(searchMatchComparer(fileMatch1, fileMatch2, SearchSortOrder.FileNames) > 0); // By type, bar.a < bar.b - assert(searchMatchComparer(fileMatch3, fileMatch4, SearchSortOrderConfiguration.type) < 0); + assert(searchMatchComparer(fileMatch3, fileMatch4, SearchSortOrder.Type) < 0); }); function aFileMatch(path: string, searchResult?: SearchResult, ...lineMatches: ITextSearchMatch[]): FileMatch { diff --git a/src/vs/workbench/services/search/common/search.ts b/src/vs/workbench/services/search/common/search.ts index 19da495ac20..4ef600d4629 100644 --- a/src/vs/workbench/services/search/common/search.ts +++ b/src/vs/workbench/services/search/common/search.ts @@ -311,13 +311,13 @@ export class OneLineRange extends SearchRange { } } -export const enum SearchSortOrderConfiguration { - default, - fileNames, - type, - modified, - countDescending, - countAscending +export const enum SearchSortOrder { + Default = 'default', + FileNames = 'fileNames', + Type = 'type', + Modified = 'modified', + CountDescending = 'countDescending', + CountAscending = 'countAscending' } export interface ISearchConfigurationProperties { @@ -342,7 +342,7 @@ export interface ISearchConfigurationProperties { searchOnTypeDebouncePeriod: number; enableSearchEditorPreview: boolean; searchEditorPreviewForceAbsolutePaths: boolean; - sortOrder: SearchSortOrderConfiguration; + sortOrder: SearchSortOrder; } export interface ISearchConfiguration extends IFilesConfiguration { -- GitLab