Make returned editor contributions an iterable instead of an array (#163309)

This lets us avoid having to call `.slice(0)` for the contributions
This commit is contained in:
Matt Bierner
2022-10-11 09:35:32 -07:00
committed by GitHub
parent 63351a794f
commit 90054ae22f
10 changed files with 30 additions and 35 deletions

View File

@@ -24,6 +24,7 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { IDisposable } from 'vs/base/common/lifecycle';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { ILogService } from 'vs/platform/log/common/log';
import { Iterable } from 'vs/base/common/iterator';
export type ServicesAccessor = InstantiationServicesAccessor;
@@ -490,15 +491,15 @@ export namespace EditorExtensionsRegistry {
return EditorContributionRegistry.INSTANCE.getEditorActions();
}
export function getEditorContributions(): IEditorContributionDescription[] {
export function getEditorContributions(): Iterable<IEditorContributionDescription> {
return EditorContributionRegistry.INSTANCE.getEditorContributions();
}
export function getSomeEditorContributions(ids: string[]): IEditorContributionDescription[] {
return EditorContributionRegistry.INSTANCE.getEditorContributions().filter(c => ids.indexOf(c.id) >= 0);
export function getSomeEditorContributions(ids: string[]): Iterable<IEditorContributionDescription> {
return Iterable.filter(EditorContributionRegistry.INSTANCE.getEditorContributions(), c => ids.indexOf(c.id) >= 0);
}
export function getDiffEditorContributions(): IDiffEditorContributionDescription[] {
export function getDiffEditorContributions(): Iterable<IDiffEditorContributionDescription> {
return EditorContributionRegistry.INSTANCE.getDiffEditorContributions();
}
}
@@ -528,16 +529,16 @@ class EditorContributionRegistry {
this.editorContributions.push({ id, ctor: ctor as IEditorContributionCtor });
}
public getEditorContributions(): IEditorContributionDescription[] {
return this.editorContributions.slice(0);
public getEditorContributions(): Iterable<IEditorContributionDescription> {
return this.editorContributions;
}
public registerDiffEditorContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: IDiffEditor, ...services: Services): IEditorContribution }): void {
this.diffEditorContributions.push({ id, ctor: ctor as IDiffEditorContributionCtor });
}
public getDiffEditorContributions(): IDiffEditorContributionDescription[] {
return this.diffEditorContributions.slice(0);
public getDiffEditorContributions(): Iterable<IDiffEditorContributionDescription> {
return this.diffEditorContributions;
}
public registerEditorAction(action: EditorAction) {