diff --git a/src/vs/workbench/api/common/extHostTestItem.ts b/src/vs/workbench/api/common/extHostTestItem.ts index 7807782afd7..35440b3b0fc 100644 --- a/src/vs/workbench/api/common/extHostTestItem.ts +++ b/src/vs/workbench/api/common/extHostTestItem.ts @@ -4,11 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import * as editorRange from 'vs/editor/common/core/range'; import { createPrivateApiFor, getPrivateApiFor, IExtHostTestItemApi } from 'vs/workbench/api/common/extHostTestingPrivateApi'; -import { TestIdPathParts } from 'vs/workbench/contrib/testing/common/testId'; +import { TestId, TestIdPathParts } from 'vs/workbench/contrib/testing/common/testId'; import { createTestItemChildren, ExtHostTestItemEvent, ITestChildrenLike, ITestItemApi, ITestItemChildren, TestItemCollection, TestItemEventOp } from 'vs/workbench/contrib/testing/common/testItemCollection'; -import { ITestItem } from 'vs/workbench/contrib/testing/common/testTypes'; +import { denamespaceTestTag, ITestItem, ITestItemContext } from 'vs/workbench/contrib/testing/common/testTypes'; import type * as vscode from 'vscode'; import * as Convert from 'vs/workbench/api/common/extHostTypeConverters'; +import { URI } from 'vs/base/common/uri'; const testItemPropAccessor = ( api: IExtHostTestItemApi, @@ -83,6 +84,27 @@ const makePropDescriptors = (api: IExtHostTestItemApi, label: string): { [K in k })), }); +const toItemFromPlain = (item: ITestItem.Serialized): TestItemImpl => { + const testId = TestId.fromString(item.extId); + const testItem = new TestItemImpl(testId.controllerId, testId.localId, item.label, URI.revive(item.uri) || undefined); + testItem.range = Convert.Range.to(item.range || undefined); + testItem.description = item.description || undefined; + testItem.sortText = item.sortText || undefined; + testItem.tags = item.tags.map(t => Convert.TestTag.to({ id: denamespaceTestTag(t).tagId })); + return testItem; +}; + +export const toItemFromContext = (context: ITestItemContext): TestItemImpl => { + let node: TestItemImpl | undefined; + for (const test of context.tests) { + const next = toItemFromPlain(test.item); + getPrivateApiFor(next).parent = node; + node = next; + } + + return node!; +}; + export class TestItemImpl implements vscode.TestItem { public readonly id!: string; public readonly uri!: vscode.Uri | undefined; diff --git a/src/vs/workbench/api/common/extHostTesting.ts b/src/vs/workbench/api/common/extHostTesting.ts index 0fb81ed4046..a7c81eb67d2 100644 --- a/src/vs/workbench/api/common/extHostTesting.ts +++ b/src/vs/workbench/api/common/extHostTesting.ts @@ -17,7 +17,7 @@ import { generateUuid } from 'vs/base/common/uuid'; import { ExtHostTestingShape, ILocationDto, MainContext, MainThreadTestingShape } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; -import { ExtHostTestItemCollection, TestItemImpl, TestItemRootImpl } from 'vs/workbench/api/common/extHostTestItem'; +import { ExtHostTestItemCollection, TestItemImpl, TestItemRootImpl, toItemFromContext } from 'vs/workbench/api/common/extHostTestItem'; import * as Convert from 'vs/workbench/api/common/extHostTypeConverters'; import { TestRunProfileKind, TestRunRequest } from 'vs/workbench/api/common/extHostTypes'; import { TestId, TestIdPathParts, TestPosition } from 'vs/workbench/contrib/testing/common/testId'; @@ -48,7 +48,7 @@ export class ExtHostTesting implements ExtHostTestingShape { commands.registerArgumentProcessor({ processArgument: arg => - arg?.$mid === MarshalledId.TestItemContext ? Convert.TestItem.toItemFromContext(arg) : arg, + arg?.$mid === MarshalledId.TestItemContext ? toItemFromContext(arg) : arg, }); } diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 9ea7d1585bb..b1874a73422 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -32,7 +32,7 @@ import * as notebooks from 'vs/workbench/contrib/notebook/common/notebookCommon' import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import * as search from 'vs/workbench/contrib/search/common/search'; import { TestId } from 'vs/workbench/contrib/testing/common/testId'; -import { CoverageDetails, denamespaceTestTag, DetailType, ICoveredCount, IFileCoverage, ISerializedTestResults, ITestErrorMessage, ITestItem, ITestItemContext, ITestTag, namespaceTestTag, TestMessageType, TestResultItem } from 'vs/workbench/contrib/testing/common/testTypes'; +import { CoverageDetails, denamespaceTestTag, DetailType, ICoveredCount, IFileCoverage, ISerializedTestResults, ITestErrorMessage, ITestItem, ITestTag, namespaceTestTag, TestMessageType, TestResultItem } from 'vs/workbench/contrib/testing/common/testTypes'; import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import type * as vscode from 'vscode'; @@ -1786,25 +1786,6 @@ export namespace TestItem { sortText: item.sortText || undefined, }; } - - export function toItemFromContext(context: ITestItemContext): vscode.TestItem { - let node: vscode.TestItem | undefined; - for (const test of context.tests) { - const next = toPlain(test.item); - (node as any).children = { - add: () => { }, - delete: () => { }, - forEach(fn) { fn(next, this); }, - get: id => id === test.item.extId ? test.item : undefined, - replace: () => { }, - size: 1, - } as vscode.TestItemCollection; - (next as any).parent = node; - node = next; - } - - return node!; - } } export namespace TestTag {