Skip to content

Commit

Permalink
es6 - use more find over filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed May 4, 2020
1 parent fa63b8e commit b19b7a7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {

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

Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/node/cliProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class Main {

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

if (newer && !force) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ suite('Disk File Service', function () {
assert.equal(resolved.isDirectory, true);
assert.equal(resolved.children!.length, 9);

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

assert.ok(!resolvedLink?.isDirectory);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/windows/electron-main/windowsMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
if (!currentWindowsState.lastActiveWindow) {
let activeWindow = this.getLastActiveWindow();
if (!activeWindow || activeWindow.isExtensionDevelopmentHost) {
activeWindow = WindowsMainService.WINDOWS.filter(window => !window.isExtensionDevelopmentHost)[0];
activeWindow = WindowsMainService.WINDOWS.find(window => !window.isExtensionDevelopmentHost);
}

if (activeWindow) {
Expand All @@ -327,7 +327,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
}

// 2.) Find extension host window
const extensionHostWindow = WindowsMainService.WINDOWS.filter(window => window.isExtensionDevelopmentHost && !window.isExtensionTestHost)[0];
const extensionHostWindow = WindowsMainService.WINDOWS.find(window => window.isExtensionDevelopmentHost && !window.isExtensionTestHost);
if (extensionHostWindow) {
currentWindowsState.lastPluginDevelopmentHostWindow = this.toWindowState(extensionHostWindow);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/windows/node/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function findWindowOnFilePath<W extends IWindowContext>(windows: W[], fileUri: U
export function getLastActiveWindow<W extends IWindowContext>(windows: W[]): W | undefined {
const lastFocusedDate = Math.max.apply(Math, windows.map(window => window.lastFocusTime));

return windows.filter(window => window.lastFocusTime === lastFocusedDate)[0];
return windows.find(window => window.lastFocusTime === lastFocusedDate);
}

export function findWindowOnWorkspace<W extends IWindowContext>(windows: W[], workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)): W | null {
Expand Down
21 changes: 10 additions & 11 deletions src/vs/workbench/api/common/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,16 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {

// ---- workspace folder picker

showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Promise<WorkspaceFolder | undefined> {
return this._commands.executeCommand<WorkspaceFolder>('_workbench.pickWorkspaceFolder', [options]).then(async (selectedFolder: WorkspaceFolder) => {
if (!selectedFolder) {
return undefined;
}
const workspaceFolders = await this._workspace.getWorkspaceFolders2();
if (!workspaceFolders) {
return undefined;
}
return workspaceFolders.filter(folder => folder.uri.toString() === selectedFolder.uri.toString())[0];
});
async showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Promise<WorkspaceFolder | undefined> {
const selectedFolder = await this._commands.executeCommand<WorkspaceFolder>('_workbench.pickWorkspaceFolder', [options]);
if (!selectedFolder) {
return undefined;
}
const workspaceFolders = await this._workspace.getWorkspaceFolders2();
if (!workspaceFolders) {
return undefined;
}
return workspaceFolders.find(folder => folder.uri.toString() === selectedFolder.uri.toString());
}

// ---- QuickInput
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export abstract class CompositeRegistry<T extends Composite> extends Disposable
private readonly _onDidDeregister = this._register(new Emitter<CompositeDescriptor<T>>());
readonly onDidDeregister = this._onDidDeregister.event;

private composites: CompositeDescriptor<T>[] = [];
private readonly composites: CompositeDescriptor<T>[] = [];

protected registerComposite(descriptor: CompositeDescriptor<T>): void {
if (this.compositeById(descriptor.id)) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/editor/editorControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class EditorControl extends Disposable {
private doInstantiateEditorPane(descriptor: IEditorDescriptor): BaseEditor {

// Return early if already instantiated
const existingEditorPane = this.editorPanes.filter(editorPane => descriptor.describes(editorPane))[0];
const existingEditorPane = this.editorPanes.find(editorPane => descriptor.describes(editorPane));
if (existingEditorPane) {
return existingEditorPane;
}
Expand Down

0 comments on commit b19b7a7

Please sign in to comment.