diff --git a/src/tsconfig.vscode-dts.json b/src/tsconfig.vscode-dts.json index 4ae9bc7643a..b8607658396 100644 --- a/src/tsconfig.vscode-dts.json +++ b/src/tsconfig.vscode-dts.json @@ -14,6 +14,7 @@ "types": [], "lib": [ "es5", + "ES2015.Iterable" ], }, "include": [ diff --git a/src/vs/workbench/api/common/extHostDiagnostics.ts b/src/vs/workbench/api/common/extHostDiagnostics.ts index 3eb7aeb41cc..d0581d21faf 100644 --- a/src/vs/workbench/api/common/extHostDiagnostics.ts +++ b/src/vs/workbench/api/common/extHostDiagnostics.ts @@ -179,9 +179,16 @@ export class DiagnosticCollection implements vscode.DiagnosticCollection { } forEach(callback: (uri: URI, diagnostics: ReadonlyArray, collection: DiagnosticCollection) => any, thisArg?: any): void { + this._checkDisposed(); + for (const [uri, values] of this) { + callback.call(thisArg, uri, values, this); + } + } + + *[Symbol.iterator](): IterableIterator<[uri: vscode.Uri, diagnostics: readonly vscode.Diagnostic[]]> { this._checkDisposed(); for (const uri of this.#data.keys()) { - callback.apply(thisArg, [uri, this.get(uri), this]); + yield [uri, this.get(uri)]; } } diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 9a898fcfe4a..f27f16dca52 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -876,6 +876,10 @@ export class EnvironmentVariableCollection implements vscode.EnvironmentVariable this.map.forEach((value, key) => callback.call(thisArg, key, value, this)); } + [Symbol.iterator](): IterableIterator<[variable: string, mutator: vscode.EnvironmentVariableMutator]> { + return this.map.entries(); + } + delete(variable: string): void { this.map.delete(variable); this._onDidChangeCollection.fire(); diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 956ba5dc9c5..9b733dc8951 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1777,6 +1777,7 @@ export namespace TestItem { add: () => { }, delete: () => { }, forEach: () => { }, + *[Symbol.iterator]() { }, get: () => undefined, replace: () => { }, size: 0, diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index b4dfa9ec1de..ce30f68d26e 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -2441,7 +2441,7 @@ export class DataTransferItem { } @es5ClassCompat -export class DataTransfer { +export class DataTransfer implements vscode.DataTransfer { #items = new Map(); constructor(init?: Iterable) { @@ -2472,6 +2472,14 @@ export class DataTransfer { } } } + + *[Symbol.iterator](): IterableIterator<[mimeType: string, item: vscode.DataTransferItem]> { + for (const [mime, items] of this.#items) { + for (const item of items) { + yield [mime, item]; + } + } + } } @es5ClassCompat diff --git a/src/vs/workbench/api/test/browser/extHostTesting.test.ts b/src/vs/workbench/api/test/browser/extHostTesting.test.ts index c4ce107acf1..2ab14e477a1 100644 --- a/src/vs/workbench/api/test/browser/extHostTesting.test.ts +++ b/src/vs/workbench/api/test/browser/extHostTesting.test.ts @@ -36,8 +36,8 @@ const assertTreesEqual = (a: TestItemImpl | undefined, b: TestItemImpl | undefin assert.deepStrictEqual(simplify(a), simplify(b)); - const aChildren = [...a.children].map(c => c.id).sort(); - const bChildren = [...b.children].map(c => c.id).sort(); + const aChildren = [...a.children].map(([_, c]) => c.id).sort(); + const bChildren = [...b.children].map(([_, c]) => c.id).sort(); assert.strictEqual(aChildren.length, bChildren.length, `expected ${a.label}.children.length == ${b.label}.children.length`); aChildren.forEach(key => assertTreesEqual(a.children.get(key) as TestItemImpl, b.children.get(key) as TestItemImpl)); }; @@ -242,7 +242,7 @@ suite('ExtHost Testing', () => { const oldA = single.root.children.get('id-a') as TestItemImpl; const newA = new TestItemImpl('ctrlId', 'id-a', 'Hello world', undefined); - newA.children.replace([...oldA.children]); + newA.children.replace([...oldA.children].map(([_, item]) => item)); single.root.children.replace([ newA, new TestItemImpl('ctrlId', 'id-b', single.root.children.get('id-b')!.label, undefined), @@ -334,7 +334,7 @@ suite('ExtHost Testing', () => { }, ]); - assert.deepStrictEqual([...single.root.children], [single.root.children.get('id-a')]); + assert.deepStrictEqual([...single.root.children].map(([_, item]) => item), [single.root.children.get('id-a')]); assert.deepStrictEqual(b.parent, a); }); }); diff --git a/src/vs/workbench/contrib/testing/common/testItemCollection.ts b/src/vs/workbench/contrib/testing/common/testItemCollection.ts index 06ad3b1b4b7..9a72a25c1ac 100644 --- a/src/vs/workbench/contrib/testing/common/testItemCollection.ts +++ b/src/vs/workbench/contrib/testing/common/testItemCollection.ts @@ -134,7 +134,7 @@ const diffTestItems = (a: ITestItem, b: ITestItem) => { return output as Partial | undefined; }; -export interface ITestChildrenLike extends Iterable { +export interface ITestChildrenLike extends Iterable<[string, T]> { get(id: string): T | undefined; delete(id: string): void; } @@ -356,7 +356,7 @@ export class TestItemCollection extends Disposable { this.connectItemAndChildren(actual, internal, parent); // Remove any orphaned children. - for (const child of oldChildren) { + for (const [_, child] of oldChildren) { if (!this.options.getChildren(actual).get(child.id)) { this.removeItem(TestId.joinToString(fullId, child.id)); } @@ -417,7 +417,7 @@ export class TestItemCollection extends Disposable { this.connectItem(actual, internal, parent); // Discover any existing children that might have already been added - for (const child of this.options.getChildren(actual)) { + for (const [_, child] of this.options.getChildren(actual)) { this.upsertItem(child, internal); } } @@ -464,7 +464,7 @@ export class TestItemCollection extends Disposable { } const expandRequests: Promise[] = []; - for (const child of this.options.getChildren(internal.actual)) { + for (const [_, child] of this.options.getChildren(internal.actual)) { const promise = this.expand(TestId.joinToString(internal.fullId, child.id), levels); if (isThenable(promise)) { expandRequests.push(promise); @@ -544,7 +544,7 @@ export class TestItemCollection extends Disposable { } this.tree.delete(item.fullId.toString()); - for (const child of this.options.getChildren(item.actual)) { + for (const [_, child] of this.options.getChildren(item.actual)) { queue.push(this.tree.get(TestId.joinToString(item.fullId, child.id))); } } @@ -561,8 +561,8 @@ export class TestItemCollection extends Disposable { } } -/** Implementation os vscode.TestItemCollection */ -export interface ITestItemChildren extends Iterable { +/** Implementation of vscode.TestItemCollection */ +export interface ITestItemChildren extends Iterable<[string, T]> { readonly size: number; replace(items: readonly T[]): void; forEach(callback: (item: T, collection: this) => unknown, thisArg?: unknown): void; @@ -607,6 +607,11 @@ export const createTestItemChildren = (api: ITestItemAp } }, + /** @inheritdoc */ + [Symbol.iterator](): IterableIterator<[string, T]> { + return mapped.entries(); + }, + /** @inheritdoc */ replace(items: Iterable) { const newMapped = new Map(); @@ -670,10 +675,5 @@ export const createTestItemChildren = (api: ITestItemAp toJSON() { return Array.from(mapped.values()); }, - - /** @inheritdoc */ - [Symbol.iterator]() { - return mapped.values(); - }, }; }; diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index c94a4461885..070cb2adafc 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -5980,7 +5980,7 @@ declare module 'vscode' { * To get an instance of a `DiagnosticCollection` use * {@link languages.createDiagnosticCollection createDiagnosticCollection}. */ - export interface DiagnosticCollection { + export interface DiagnosticCollection extends Iterable<[uri: Uri, diagnostics: readonly Diagnostic[]]> { /** * The name of this diagnostic collection, for instance `typescript`. Every diagnostic @@ -10120,7 +10120,7 @@ declare module 'vscode' { * data transfer. These additional mime types will only be included in the `handleDrop` when the the drag was initiated from * an element in the same drag and drop controller. */ - export class DataTransfer { + export class DataTransfer implements Iterable<[mimeType: string, item: DataTransferItem]> { /** * Retrieves the data transfer item for a given mime type. * @@ -10146,6 +10146,11 @@ declare module 'vscode' { * @param thisArg The `this` context used when invoking the handler function. */ forEach(callbackfn: (value: DataTransferItem, key: string, dataTransfer: DataTransfer) => void, thisArg?: any): void; + + /** + * Get a new iterator with the `[mime, item]` pairs for each element in this data transfer. + */ + [Symbol.iterator](): IterableIterator<[mimeType: string, item: DataTransferItem]>; } /** @@ -10812,7 +10817,7 @@ declare module 'vscode' { /** * A collection of mutations that an extension can apply to a process environment. */ - export interface EnvironmentVariableCollection { + export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { /** * Whether the collection should be cached for the workspace and applied to the terminal * across window reloads. When true the collection will be active immediately such when the @@ -15681,7 +15686,7 @@ declare module 'vscode' { * Collection of test items, found in {@link TestItem.children} and * {@link TestController.items}. */ - export interface TestItemCollection { + export interface TestItemCollection extends Iterable<[id: string, testItem: TestItem]> { /** * Gets the number of items in the collection. */