Skip to content

Commit b19b7a7

Browse files
author
Benjamin Pasero
committed
es6 - use more find over filter
1 parent fa63b8e commit b19b7a7

8 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/vs/code/electron-main/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
937937

938938
// Multi Montior (fullscreen): try to find the previously used display
939939
if (state.display && state.mode === WindowMode.Fullscreen) {
940-
const display = displays.filter(d => d.id === state.display)[0];
940+
const display = displays.find(d => d.id === state.display);
941941
if (display && typeof display.bounds?.x === 'number' && typeof display.bounds?.y === 'number') {
942942
this.logService.trace('window#validateWindowState: restoring fullscreen to previous display');
943943

src/vs/code/node/cliProcessMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class Main {
216216

217217
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
218218
const installedExtensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
219-
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, local.identifier) && semver.gt(local.manifest.version, manifest.version))[0];
219+
const newer = installedExtensions.find(local => areSameExtensions(extensionIdentifier, local.identifier) && semver.gt(local.manifest.version, manifest.version));
220220

221221
if (newer && !force) {
222222
console.log(localize('forceDowngrade', "A newer version of extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.identifier.id, newer.manifest.version, manifest.version));

src/vs/platform/files/test/electron-browser/diskFileService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ suite('Disk File Service', function () {
441441
assert.equal(resolved.isDirectory, true);
442442
assert.equal(resolved.children!.length, 9);
443443

444-
const resolvedLink = resolved.children?.filter(child => child.name === 'bar' && child.isSymbolicLink)[0];
444+
const resolvedLink = resolved.children?.find(child => child.name === 'bar' && child.isSymbolicLink);
445445
assert.ok(resolvedLink);
446446

447447
assert.ok(!resolvedLink?.isDirectory);

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
318318
if (!currentWindowsState.lastActiveWindow) {
319319
let activeWindow = this.getLastActiveWindow();
320320
if (!activeWindow || activeWindow.isExtensionDevelopmentHost) {
321-
activeWindow = WindowsMainService.WINDOWS.filter(window => !window.isExtensionDevelopmentHost)[0];
321+
activeWindow = WindowsMainService.WINDOWS.find(window => !window.isExtensionDevelopmentHost);
322322
}
323323

324324
if (activeWindow) {
@@ -327,7 +327,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
327327
}
328328

329329
// 2.) Find extension host window
330-
const extensionHostWindow = WindowsMainService.WINDOWS.filter(window => window.isExtensionDevelopmentHost && !window.isExtensionTestHost)[0];
330+
const extensionHostWindow = WindowsMainService.WINDOWS.find(window => window.isExtensionDevelopmentHost && !window.isExtensionTestHost);
331331
if (extensionHostWindow) {
332332
currentWindowsState.lastPluginDevelopmentHostWindow = this.toWindowState(extensionHostWindow);
333333
}

src/vs/platform/windows/node/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function findWindowOnFilePath<W extends IWindowContext>(windows: W[], fileUri: U
168168
export function getLastActiveWindow<W extends IWindowContext>(windows: W[]): W | undefined {
169169
const lastFocusedDate = Math.max.apply(Math, windows.map(window => window.lastFocusTime));
170170

171-
return windows.filter(window => window.lastFocusTime === lastFocusedDate)[0];
171+
return windows.find(window => window.lastFocusTime === lastFocusedDate);
172172
}
173173

174174
export function findWindowOnWorkspace<W extends IWindowContext>(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W | null {

src/vs/workbench/api/common/extHostQuickOpen.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,16 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
159159

160160
// ---- workspace folder picker
161161

162-
showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Promise<WorkspaceFolder | undefined> {
163-
return this._commands.executeCommand<WorkspaceFolder>('_workbench.pickWorkspaceFolder', [options]).then(async (selectedFolder: WorkspaceFolder) => {
164-
if (!selectedFolder) {
165-
return undefined;
166-
}
167-
const workspaceFolders = await this._workspace.getWorkspaceFolders2();
168-
if (!workspaceFolders) {
169-
return undefined;
170-
}
171-
return workspaceFolders.filter(folder => folder.uri.toString() === selectedFolder.uri.toString())[0];
172-
});
162+
async showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Promise<WorkspaceFolder | undefined> {
163+
const selectedFolder = await this._commands.executeCommand<WorkspaceFolder>('_workbench.pickWorkspaceFolder', [options]);
164+
if (!selectedFolder) {
165+
return undefined;
166+
}
167+
const workspaceFolders = await this._workspace.getWorkspaceFolders2();
168+
if (!workspaceFolders) {
169+
return undefined;
170+
}
171+
return workspaceFolders.find(folder => folder.uri.toString() === selectedFolder.uri.toString());
173172
}
174173

175174
// ---- QuickInput

src/vs/workbench/browser/composite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export abstract class CompositeRegistry<T extends Composite> extends Disposable
255255
private readonly _onDidDeregister = this._register(new Emitter<CompositeDescriptor<T>>());
256256
readonly onDidDeregister = this._onDidDeregister.event;
257257

258-
private composites: CompositeDescriptor<T>[] = [];
258+
private readonly composites: CompositeDescriptor<T>[] = [];
259259

260260
protected registerComposite(descriptor: CompositeDescriptor<T>): void {
261261
if (this.compositeById(descriptor.id)) {

src/vs/workbench/browser/parts/editor/editorControl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class EditorControl extends Disposable {
123123
private doInstantiateEditorPane(descriptor: IEditorDescriptor): BaseEditor {
124124

125125
// Return early if already instantiated
126-
const existingEditorPane = this.editorPanes.filter(editorPane => descriptor.describes(editorPane))[0];
126+
const existingEditorPane = this.editorPanes.find(editorPane => descriptor.describes(editorPane));
127127
if (existingEditorPane) {
128128
return existingEditorPane;
129129
}

0 commit comments

Comments
 (0)