From cf8adf02815ca1348fc9a2f350158b6a2d8c627a Mon Sep 17 00:00:00 2001 From: Simon McEnlly Date: Thu, 2 Sep 2021 14:45:41 +1000 Subject: [PATCH] testing: add new API `sortText` property to TestItem; if populated will be used instead of `label` for sorting items in Test Explorer tree and list view --- src/vs/vscode.d.ts | 6 ++++++ src/vs/workbench/api/common/extHostTestingPrivateApi.ts | 5 ++++- src/vs/workbench/api/common/extHostTypeConverters.ts | 3 +++ .../contrib/testing/browser/explorerProjections/index.ts | 4 ++++ .../contrib/testing/browser/testingExplorerView.ts | 2 +- src/vs/workbench/contrib/testing/common/testCollection.ts | 1 + 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 067cf63be16..8825c3e246e 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -14292,6 +14292,12 @@ declare module 'vscode' { */ description?: string; + /** + * Optional sortText to sort the test items by. If sort text exists on a + * {@link TestItem} then it is used instead of {@link TestItem.label}. + */ + sortText?: string; + /** * Location of the test item in its {@link uri}. * diff --git a/src/vs/workbench/api/common/extHostTestingPrivateApi.ts b/src/vs/workbench/api/common/extHostTestingPrivateApi.ts index 270de0bd118..26c7081cce3 100644 --- a/src/vs/workbench/api/common/extHostTestingPrivateApi.ts +++ b/src/vs/workbench/api/common/extHostTestingPrivateApi.ts @@ -95,7 +95,7 @@ const testItemPropAccessor = ( }; }; -type WritableProps = Pick; +type WritableProps = Pick; const strictEqualComparator = (a: T, b: T) => a === b; @@ -107,6 +107,7 @@ const propComparators: { [K in keyof Required]: (a: vscode.TestIt }, label: strictEqualComparator, description: strictEqualComparator, + sortText: strictEqualComparator, busy: strictEqualComparator, error: strictEqualComparator, canResolveChildren: strictEqualComparator, @@ -129,6 +130,7 @@ const makePropDescriptors = (api: IExtHostTestItemApi, label: string): { [K in k range: testItemPropAccessor(api, 'range', undefined, propComparators.range), label: testItemPropAccessor(api, 'label', label, propComparators.label), description: testItemPropAccessor(api, 'description', undefined, propComparators.description), + sortText: testItemPropAccessor(api, 'sortText', undefined, propComparators.sortText), canResolveChildren: testItemPropAccessor(api, 'canResolveChildren', false, propComparators.canResolveChildren), busy: testItemPropAccessor(api, 'busy', false, propComparators.busy), error: testItemPropAccessor(api, 'error', undefined, propComparators.error), @@ -268,6 +270,7 @@ export class TestItemImpl implements vscode.TestItem { public range!: vscode.Range | undefined; public description!: string | undefined; + public sortText!: string | undefined; public label!: string; public error!: string | vscode.MarkdownString; public busy!: boolean; diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 3e9b18aafa9..185af86bcc1 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1685,6 +1685,7 @@ export namespace TestItem { tags: item.tags.map(t => TestTag.namespace(ctrlId, t.id)), range: Range.from(item.range) || null, description: item.description || null, + sortText: item.sortText || null, error: item.error ? (MarkdownString.fromStrict(item.error) || null) : null, }; } @@ -1703,6 +1704,7 @@ export namespace TestItem { canResolveChildren: false, busy: false, description: item.description || undefined, + sortText: item.sortText || undefined, }; } @@ -1711,6 +1713,7 @@ export namespace TestItem { const testItem = new TestItemImpl(testId.controllerId, testId.localId, item.label, URI.revive(item.uri)); testItem.range = Range.to(item.range || undefined); testItem.description = item.description || undefined; + testItem.sortText = item.sortText || undefined; return testItem; } diff --git a/src/vs/workbench/contrib/testing/browser/explorerProjections/index.ts b/src/vs/workbench/contrib/testing/browser/explorerProjections/index.ts index 932c2a40de5..734d3d90d51 100644 --- a/src/vs/workbench/contrib/testing/browser/explorerProjections/index.ts +++ b/src/vs/workbench/contrib/testing/browser/explorerProjections/index.ts @@ -115,6 +115,10 @@ export class TestItemTreeElement implements IActionableTestTreeElement { return this.test.item.description; } + public get sortText() { + return this.test.item.sortText; + } + /** * Whether the node's test result is 'retired' -- from an outdated test run. */ diff --git a/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts b/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts index 7fcd0779b87..00b81adb496 100644 --- a/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts +++ b/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts @@ -948,7 +948,7 @@ class TreeSorter implements ITreeSorter { } } - return a.label.localeCompare(b.label); + return (a.sortText || a.label).localeCompare((b.sortText || b.label)); } } diff --git a/src/vs/workbench/contrib/testing/common/testCollection.ts b/src/vs/workbench/contrib/testing/common/testCollection.ts index 9646aefa17a..c4349e4e04d 100644 --- a/src/vs/workbench/contrib/testing/common/testCollection.ts +++ b/src/vs/workbench/contrib/testing/common/testCollection.ts @@ -160,6 +160,7 @@ export interface ITestItem { range: IRange | null; description: string | null; error: string | IMarkdownString | null; + sortText: string | null; } export const enum TestItemExpandState {