mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Use array.find in more places of re-implementing it with for loops
This commit is contained in:
@@ -20,7 +20,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { MarkerNavigationWidget } from './gotoErrorWidget';
|
||||
import { compare } from 'vs/base/common/strings';
|
||||
import { binarySearch } from 'vs/base/common/arrays';
|
||||
import { binarySearch, find } from 'vs/base/common/arrays';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
|
||||
@@ -173,12 +173,7 @@ class MarkerModel {
|
||||
}
|
||||
|
||||
public findMarkerAtPosition(pos: Position): IMarker | undefined {
|
||||
for (const marker of this._markers) {
|
||||
if (Range.containsPosition(marker, pos)) {
|
||||
return marker;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return find(this._markers, marker => Range.containsPosition(marker, pos));
|
||||
}
|
||||
|
||||
public get total() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { StandardTokenType } from 'vs/editor/common/modes';
|
||||
import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair';
|
||||
import { TokenText, createFakeScopedLineTokens } from 'vs/editor/test/common/modesTestUtils';
|
||||
import { StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
suite('CharacterPairSupport', () => {
|
||||
|
||||
@@ -53,13 +54,8 @@ suite('CharacterPairSupport', () => {
|
||||
assert.deepEqual(characaterPairSupport.getSurroundingPairs(), []);
|
||||
});
|
||||
|
||||
function findAutoClosingPair(characterPairSupport: CharacterPairSupport, character: string): StandardAutoClosingPairConditional | null {
|
||||
for (const autoClosingPair of characterPairSupport.getAutoClosingPairs()) {
|
||||
if (autoClosingPair.open === character) {
|
||||
return autoClosingPair;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
function findAutoClosingPair(characterPairSupport: CharacterPairSupport, character: string): StandardAutoClosingPairConditional | undefined {
|
||||
return find(characterPairSupport.getAutoClosingPairs(), autoClosingPair => autoClosingPair.open === character);
|
||||
}
|
||||
|
||||
function testShouldAutoClose(characterPairSupport: CharacterPairSupport, line: TokenText[], character: string, column: number): boolean {
|
||||
|
||||
@@ -21,19 +21,13 @@ import { isLinux, isWindows } from 'vs/base/common/platform';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { isEqual } from 'vs/base/common/resources';
|
||||
import { VSBuffer, VSBufferReadable, toVSBufferReadableStream, VSBufferReadableStream, bufferToReadable, bufferToStream } from 'vs/base/common/buffer';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
function getByName(root: IFileStat, name: string): IFileStat | null {
|
||||
function getByName(root: IFileStat, name: string): IFileStat | undefined {
|
||||
if (root.children === undefined) {
|
||||
return null;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
for (const child of root.children) {
|
||||
if (child.name === name) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return find(root.children, child => child.name === name);
|
||||
}
|
||||
|
||||
function toLineByLineReadable(content: string): VSBufferReadable {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
|
||||
import { IConstructorSignature0, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export interface IEditorDescriptor {
|
||||
instantiate(instantiationService: IInstantiationService): BaseEditor;
|
||||
@@ -140,13 +141,7 @@ class EditorRegistry implements IEditorRegistry {
|
||||
}
|
||||
|
||||
getEditorById(editorId: string): EditorDescriptor | undefined {
|
||||
for (const editor of this.editors) {
|
||||
if (editor.getId() === editorId) {
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return find(this.editors, editor => editor.getId() === editorId);
|
||||
}
|
||||
|
||||
getEditors(): readonly EditorDescriptor[] {
|
||||
|
||||
@@ -16,6 +16,7 @@ import { GroupDirection, MergeGroupMode } from 'vs/workbench/services/editor/com
|
||||
import { toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
interface IDropOperation {
|
||||
splitDirection?: GroupDirection;
|
||||
@@ -544,13 +545,7 @@ export class EditorDropTarget extends Themable {
|
||||
|
||||
private findTargetGroupView(child: HTMLElement): IEditorGroupView | undefined {
|
||||
const groups = this.accessor.groups;
|
||||
for (const groupView of groups) {
|
||||
if (isAncestor(child, groupView.element)) {
|
||||
return groupView;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return find(groups, groupView => isAncestor(child, groupView.element));
|
||||
}
|
||||
|
||||
private updateContainer(isDraggedOver: boolean): void {
|
||||
|
||||
@@ -27,7 +27,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
|
||||
import { IStorageService, StorageScope, IWorkspaceStorageChangeEvent } from 'vs/platform/storage/common/storage';
|
||||
import { Parts, IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { coalesce } from 'vs/base/common/arrays';
|
||||
import { coalesce, find } from 'vs/base/common/arrays';
|
||||
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
|
||||
import { ToggleStatusbarVisibilityAction } from 'vs/workbench/browser/actions/layoutActions';
|
||||
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
@@ -176,13 +176,7 @@ class StatusbarViewModel extends Disposable {
|
||||
}
|
||||
|
||||
findEntry(container: HTMLElement): IStatusbarViewModelEntry | undefined {
|
||||
for (const entry of this._entries) {
|
||||
if (entry.container === container) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return find(this._entries, entry => entry.container === container);
|
||||
}
|
||||
|
||||
getEntries(alignment: StatusbarAlignment): IStatusbarViewModelEntry[] {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Action } from 'vs/base/common/actions';
|
||||
import { isErrorWithActions } from 'vs/base/common/errorsWithActions';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
import { localize } from 'vs/nls';
|
||||
import { find, equals } from 'vs/base/common/arrays';
|
||||
|
||||
export interface INotificationsModel {
|
||||
|
||||
@@ -169,13 +170,7 @@ export class NotificationsModel extends Disposable implements INotificationsMode
|
||||
}
|
||||
|
||||
private findNotification(item: INotificationViewItem): INotificationViewItem | undefined {
|
||||
for (const notification of this._notifications) {
|
||||
if (notification.equals(item)) {
|
||||
return notification;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return find(this._notifications, notification => notification.equals(item));
|
||||
}
|
||||
|
||||
private createViewItem(notification: INotification): INotificationViewItem | null {
|
||||
@@ -641,17 +636,7 @@ export class NotificationViewItem extends Disposable implements INotificationVie
|
||||
|
||||
const primaryActions = (this._actions && this._actions.primary) || [];
|
||||
const otherPrimaryActions = (other.actions && other.actions.primary) || [];
|
||||
if (primaryActions.length !== otherPrimaryActions.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < primaryActions.length; i++) {
|
||||
if ((primaryActions[i].id + primaryActions[i].label) !== (otherPrimaryActions[i].id + otherPrimaryActions[i].label)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return equals(primaryActions, otherPrimaryActions, (a, b) => (a.id + a.label) === (b.id + b.label));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import * as strings from 'vs/base/common/strings';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export interface ICreateData {
|
||||
workspaceFolders: string[];
|
||||
@@ -44,15 +45,9 @@ export class OutputLinkComputer {
|
||||
});
|
||||
}
|
||||
|
||||
private getModel(uri: string): IMirrorModel | null {
|
||||
private getModel(uri: string): IMirrorModel | undefined {
|
||||
const models = this.ctx.getMirrorModels();
|
||||
for (const model of models) {
|
||||
if (model.uri.toString() === uri) {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return find(models, model => model.uri.toString() === uri);
|
||||
}
|
||||
|
||||
public computeLinks(uri: string): Promise<ILink[]> {
|
||||
|
||||
@@ -32,6 +32,7 @@ import { DefaultSettingsEditorModel, SettingsEditorModel, WorkspaceConfiguration
|
||||
import { IMarkerService, IMarkerData, MarkerSeverity, MarkerTag } from 'vs/platform/markers/common/markers';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export interface IPreferencesRenderer<T> extends IDisposable {
|
||||
readonly preferencesModel: IPreferencesEditorModel<T>;
|
||||
@@ -321,12 +322,7 @@ export class DefaultSettingsRenderer extends Disposable implements IPreferencesR
|
||||
const { key, overrideOf } = setting;
|
||||
if (overrideOf) {
|
||||
const setting = this.getSetting(overrideOf);
|
||||
for (const override of setting!.overrides!) {
|
||||
if (override.key === key) {
|
||||
return override;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return find(setting!.overrides!, override => override.key === key);
|
||||
}
|
||||
const settingsGroups = this.filterResult ? this.filterResult.filteredGroups : this.preferencesModel.settingsGroups;
|
||||
return this.getPreference(key, settingsGroups);
|
||||
|
||||
@@ -77,6 +77,7 @@ import { applyEdits } from 'vs/base/common/jsonEdit';
|
||||
import { ITextEditor } from 'vs/workbench/common/editor';
|
||||
import { ITextEditorSelection } from 'vs/platform/editor/common/editor';
|
||||
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export namespace ConfigureTaskAction {
|
||||
export const ID = 'workbench.action.tasks.configureTaskRunner';
|
||||
@@ -515,12 +516,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
|
||||
if (!values) {
|
||||
return undefined;
|
||||
}
|
||||
for (const task of values) {
|
||||
if (task.matches(key, compareId)) {
|
||||
return task;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return find(values, task => task.matches(key, compareId));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import { escapeNonWindowsPath } from 'vs/workbench/contrib/terminal/common/termi
|
||||
import { isWindows, isMacintosh, OperatingSystem } from 'vs/base/common/platform';
|
||||
import { basename } from 'vs/base/common/path';
|
||||
import { IOpenFileRequest } from 'vs/platform/windows/common/windows';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
interface IExtHostReadyEntry {
|
||||
promise: Promise<void>;
|
||||
@@ -414,13 +415,8 @@ export class TerminalService implements ITerminalService {
|
||||
instance.addDisposable(instance.onFocus(this._onActiveInstanceChanged.fire, this._onActiveInstanceChanged));
|
||||
}
|
||||
|
||||
private _getTabForInstance(instance: ITerminalInstance): ITerminalTab | null {
|
||||
for (const tab of this._terminalTabs) {
|
||||
if (tab.terminalInstances.indexOf(instance) !== -1) {
|
||||
return tab;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
private _getTabForInstance(instance: ITerminalInstance): ITerminalTab | undefined {
|
||||
return find(this._terminalTabs, tab => tab.terminalInstances.indexOf(instance) !== -1);
|
||||
}
|
||||
|
||||
public showPanel(focus?: boolean): Promise<void> {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { ICredentialsService } from 'vs/platform/credentials/common/credentials';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export interface ICredentialsProvider {
|
||||
getPassword(service: string, account: string): Promise<string | null>;
|
||||
@@ -14,7 +15,7 @@ export interface ICredentialsProvider {
|
||||
deletePassword(service: string, account: string): Promise<boolean>;
|
||||
|
||||
findPassword(service: string): Promise<string | null>;
|
||||
findCredentials(service: string): Promise<Array<{ account: string, password: string }>>;
|
||||
findCredentials(service: string): Promise<Array<{ account: string, password: string; }>>;
|
||||
}
|
||||
|
||||
export class BrowserCredentialsService implements ICredentialsService {
|
||||
@@ -47,7 +48,7 @@ export class BrowserCredentialsService implements ICredentialsService {
|
||||
return this.credentialsProvider.findPassword(service);
|
||||
}
|
||||
|
||||
findCredentials(service: string): Promise<Array<{ account: string, password: string }>> {
|
||||
findCredentials(service: string): Promise<Array<{ account: string, password: string; }>> {
|
||||
return this.credentialsProvider.findCredentials(service);
|
||||
}
|
||||
}
|
||||
@@ -88,17 +89,12 @@ class InMemoryCredentialsProvider implements ICredentialsProvider {
|
||||
return credential ? credential.password : null;
|
||||
}
|
||||
|
||||
private doFindPassword(service: string, account?: string): ICredential | null {
|
||||
for (const credential of this.credentials) {
|
||||
if (credential.service === service && (typeof account !== 'string' || credential.account === account)) {
|
||||
return credential;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
private doFindPassword(service: string, account?: string): ICredential | undefined {
|
||||
return find(this.credentials, credential =>
|
||||
credential.service === service && (typeof account !== 'string' || credential.account === account));
|
||||
}
|
||||
|
||||
async findCredentials(service: string): Promise<Array<{ account: string, password: string }>> {
|
||||
async findCredentials(service: string): Promise<Array<{ account: string, password: string; }>> {
|
||||
return this.credentials
|
||||
.filter(credential => credential.service === service)
|
||||
.map(({ account, password }) => ({ account, password }));
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { FileIconThemeData } from 'vs/workbench/services/themes/browser/fileIconThemeData';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
const iconThemeExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPoint[]>({
|
||||
extensionPoint: 'iconThemes',
|
||||
@@ -62,7 +63,7 @@ export class FileIconThemeStore extends Disposable {
|
||||
|
||||
private initialize() {
|
||||
iconThemeExtPoint.setHandler((extensions) => {
|
||||
const previousIds: { [key: string]: boolean } = {};
|
||||
const previousIds: { [key: string]: boolean; } = {};
|
||||
const added: FileIconThemeData[] = [];
|
||||
for (const theme of this.knownIconThemes) {
|
||||
previousIds[theme.id] = true;
|
||||
@@ -131,12 +132,7 @@ export class FileIconThemeStore extends Disposable {
|
||||
return Promise.resolve(FileIconThemeData.noIconTheme());
|
||||
}
|
||||
return this.getFileIconThemes().then(allIconSets => {
|
||||
for (let iconSet of allIconSets) {
|
||||
if (iconSet.id === iconTheme) {
|
||||
return iconSet;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return find(allIconSets, iconSet => iconSet.id === iconTheme);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,12 +141,7 @@ export class FileIconThemeStore extends Disposable {
|
||||
return Promise.resolve(FileIconThemeData.noIconTheme());
|
||||
}
|
||||
return this.getFileIconThemes().then(allIconSets => {
|
||||
for (let iconSet of allIconSets) {
|
||||
if (iconSet.settingsId === settingsId) {
|
||||
return iconSet;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return find(allIconSets, iconSet => iconSet.settingsId === settingsId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ import { INativeOpenDialogOptions, MessageBoxReturnValue, SaveDialogReturnValue,
|
||||
import { IBackupMainService, IWorkspaceBackupInfo } from 'vs/platform/backup/electron-main/backup';
|
||||
import { IEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
|
||||
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogs';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
|
||||
return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined);
|
||||
@@ -700,14 +701,8 @@ export class TestEditorGroupsService implements IEditorGroupsService {
|
||||
return this.groups;
|
||||
}
|
||||
|
||||
getGroup(identifier: number): IEditorGroup {
|
||||
for (const group of this.groups) {
|
||||
if (group.id === identifier) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined!;
|
||||
getGroup(identifier: number): IEditorGroup | undefined {
|
||||
return find(this.groups, group => group.id === identifier);
|
||||
}
|
||||
|
||||
getLabel(_identifier: number): string {
|
||||
|
||||
Reference in New Issue
Block a user