Skip to content

Commit caa19dc

Browse files
committed
debug: use .find not .filter .pop()
1 parent 177b9c3 commit caa19dc

9 files changed

Lines changed: 28 additions & 30 deletions

File tree

src/vs/workbench/contrib/debug/browser/breakpointEditorContribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async function createCandidateDecorations(model: ITextModel, breakpointDecoratio
120120
return;
121121
}
122122

123-
const breakpointAtPosition = breakpointDecorations.filter(bpd => bpd.range.equalsRange(range)).pop();
123+
const breakpointAtPosition = breakpointDecorations.find(bpd => bpd.range.equalsRange(range));
124124
if (breakpointAtPosition && breakpointAtPosition.inlineWidget) {
125125
// Space already occupied, do not render candidate.
126126
return;

src/vs/workbench/contrib/debug/browser/callStackView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class SessionsRenderer implements ITreeRenderer<IDebugSession, FuzzyScore, ISess
473473
const session = element.element;
474474
data.session.title = nls.localize({ key: 'session', comment: ['Session is a noun'] }, "Session");
475475
data.label.set(session.getLabel(), createMatches(element.filterData));
476-
const thread = session.getAllThreads().filter(t => t.stopped).pop();
476+
const thread = session.getAllThreads().find(t => t.stopped);
477477

478478
const setActionBar = () => {
479479
const actions = getActions(this.instantiationService, element.element);
@@ -493,7 +493,7 @@ class SessionsRenderer implements ITreeRenderer<IDebugSession, FuzzyScore, ISess
493493
if (thread && thread.stoppedDetails) {
494494
data.stateLabel.textContent = thread.stoppedDetails.description || nls.localize('debugStopped', "Paused on {0}", thread.stoppedDetails.reason || '');
495495
} else {
496-
const hasChildSessions = this.debugService.getModel().getSessions().filter(s => s.parentSession === session).length > 0;
496+
const hasChildSessions = this.debugService.getModel().getSessions().find(s => s.parentSession === session);
497497
if (!hasChildSessions) {
498498
data.stateLabel.textContent = nls.localize({ key: 'running', comment: ['indicates state'] }, "Running");
499499
} else {
@@ -751,7 +751,7 @@ class CallStackDataSource implements IAsyncDataSource<IDebugModel, CallStackItem
751751
hasChildren(element: IDebugModel | CallStackItem): boolean {
752752
if (isDebugSession(element)) {
753753
const threads = element.getAllThreads();
754-
return (threads.length > 1) || (threads.length === 1 && threads[0].stopped) || (this.debugService.getModel().getSessions().filter(s => s.parentSession === element).length > 0);
754+
return (threads.length > 1) || (threads.length === 1 && threads[0].stopped) || !!(this.debugService.getModel().getSessions().find(s => s.parentSession === element));
755755
}
756756

757757
return isDebugModel(element) || (element instanceof Thread && element.stopped);

src/vs/workbench/contrib/debug/browser/debugCommands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function getThreadAndRun(accessor: ServicesAccessor, sessionAndThreadId: C
7474
if (isThreadContext(sessionAndThreadId)) {
7575
const session = debugService.getModel().getSession(sessionAndThreadId.sessionId);
7676
if (session) {
77-
thread = session.getAllThreads().filter(t => t.getId() === sessionAndThreadId.threadId).pop();
77+
thread = session.getAllThreads().find(t => t.getId() === sessionAndThreadId.threadId);
7878
}
7979
} else {
8080
thread = debugService.getViewModel().focusedThread;
@@ -98,9 +98,9 @@ function getFrame(debugService: IDebugService, context: CallStackContext | unkno
9898
if (isStackFrameContext(context)) {
9999
const session = debugService.getModel().getSession(context.sessionId);
100100
if (session) {
101-
const thread = session.getAllThreads().filter(t => t.getId() === context.threadId).pop();
101+
const thread = session.getAllThreads().find(t => t.getId() === context.threadId);
102102
if (thread) {
103-
return thread.getCallStack().filter(sf => sf.getId() === context.frameId).pop();
103+
return thread.getCallStack().find(sf => sf.getId() === context.frameId);
104104
}
105105
}
106106
}
@@ -498,7 +498,7 @@ export function registerCommands(): void {
498498
return;
499499
}
500500

501-
const launch = manager.getLaunches().filter(l => l.uri.toString() === launchUri).pop() || manager.selectedConfiguration.launch;
501+
const launch = manager.getLaunches().find(l => l.uri.toString() === launchUri) || manager.selectedConfiguration.launch;
502502
if (launch) {
503503
const { editor, created } = await launch.openConfigFile(false, false);
504504
if (editor && !created) {

src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class ConfigurationManager implements IConfigurationManager {
7979
this.initLaunches();
8080
this.registerListeners();
8181
const previousSelectedRoot = this.storageService.get(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
82-
const previousSelectedLaunch = this.launches.filter(l => l.uri.toString() === previousSelectedRoot).pop();
82+
const previousSelectedLaunch = this.launches.find(l => l.uri.toString() === previousSelectedRoot);
8383
this.debugConfigurationTypeContext = CONTEXT_DEBUG_CONFIGURATION_TYPE.bindTo(contextKeyService);
8484
if (previousSelectedLaunch && previousSelectedLaunch.getConfigurationNames().length) {
8585
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
@@ -202,8 +202,8 @@ export class ConfigurationManager implements IConfigurationManager {
202202
triggerKind = DebugConfigurationProviderTriggerKind.Initial;
203203
}
204204
// check if there are providers for the given type that contribute a provideDebugConfigurations method
205-
const providers = this.configProviders.filter(p => p.provideDebugConfigurations && (p.type === debugType) && (p.triggerKind === triggerKind));
206-
return providers.length > 0;
205+
const provider = this.configProviders.find(p => p.provideDebugConfigurations && (p.type === debugType) && (p.triggerKind === triggerKind));
206+
return !!provider;
207207
}
208208

209209
async resolveConfigurationByProviders(folderUri: uri | undefined, type: string | undefined, config: IConfig, token: CancellationToken): Promise<IConfig | null | undefined> {
@@ -416,7 +416,7 @@ export class ConfigurationManager implements IConfigurationManager {
416416
return undefined;
417417
}
418418

419-
return this.launches.filter(l => l.workspace && l.workspace.uri.toString() === workspaceUri.toString()).pop();
419+
return this.launches.find(l => l.workspace && l.workspace.uri.toString() === workspaceUri.toString());
420420
}
421421

422422
get selectedConfiguration(): { launch: ILaunch | undefined, name: string | undefined } {
@@ -490,11 +490,11 @@ export class ConfigurationManager implements IConfigurationManager {
490490
}
491491

492492
getDebugger(type: string): Debugger | undefined {
493-
return this.debuggers.filter(dbg => strings.equalsIgnoreCase(dbg.type, type)).pop();
493+
return this.debuggers.find(dbg => strings.equalsIgnoreCase(dbg.type, type));
494494
}
495495

496496
isDebuggerInterestedInLanguage(language: string): boolean {
497-
return this.debuggers.filter(a => language && a.languages && a.languages.indexOf(language) >= 0).length > 0;
497+
return !!this.debuggers.find(a => language && a.languages && a.languages.indexOf(language) >= 0);
498498
}
499499

500500
async guessDebugger(type?: string): Promise<Debugger | undefined> {
@@ -571,7 +571,7 @@ abstract class AbstractLaunch {
571571
return undefined;
572572
}
573573

574-
return config.compounds.filter(compound => compound.name === name).pop();
574+
return config.compounds.find(compound => compound.name === name);
575575
}
576576

577577
getConfigurationNames(ignoreCompoundsAndPresentation = false): string[] {
@@ -602,7 +602,7 @@ abstract class AbstractLaunch {
602602
return undefined;
603603
}
604604

605-
return config.configurations.filter(config => config && config.name === name).shift();
605+
return config.configurations.find(config => config && config.name === name);
606606
}
607607

608608
get hidden(): boolean {

src/vs/workbench/contrib/debug/browser/debugService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ export function getStackFrameThreadAndSessionToFocus(model: IDebugModel, stackFr
952952
session = stackFrame ? stackFrame.thread.session : thread!.session;
953953
} else {
954954
const sessions = model.getSessions();
955-
const stoppedSession = sessions.filter(s => s.state === State.Stopped).shift();
955+
const stoppedSession = sessions.find(s => s.state === State.Stopped);
956956
session = stoppedSession || (sessions.length ? sessions[0] : undefined);
957957
}
958958
}
@@ -962,7 +962,7 @@ export function getStackFrameThreadAndSessionToFocus(model: IDebugModel, stackFr
962962
thread = stackFrame.thread;
963963
} else {
964964
const threads = session ? session.getAllThreads() : undefined;
965-
const stoppedThread = threads && threads.filter(t => t.stopped).shift();
965+
const stoppedThread = threads && threads.find(t => t.stopped);
966966
thread = stoppedThread || (threads && threads.length ? threads[0] : undefined);
967967
}
968968
}

src/vs/workbench/contrib/debug/browser/debugSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,8 @@ export class DebugSession implements IDebugSession {
890890

891891
this.rawListeners.push(this.raw.onDidBreakpoint(event => {
892892
const id = event.body && event.body.breakpoint ? event.body.breakpoint.id : undefined;
893-
const breakpoint = this.model.getBreakpoints().filter(bp => bp.getIdFromAdapter(this.getId()) === id).pop();
894-
const functionBreakpoint = this.model.getFunctionBreakpoints().filter(bp => bp.getIdFromAdapter(this.getId()) === id).pop();
893+
const breakpoint = this.model.getBreakpoints().find(bp => bp.getIdFromAdapter(this.getId()) === id);
894+
const functionBreakpoint = this.model.getFunctionBreakpoints().find(bp => bp.getIdFromAdapter(this.getId()) === id);
895895

896896
if (event.body.reason === 'new' && event.body.breakpoint.source && event.body.breakpoint.line) {
897897
const source = this.getSource(event.body.breakpoint.source);

src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ export class DebugTaskRunner {
146146
}));
147147

148148
const promise: Promise<ITaskSummary | null> = this.taskService.getActiveTasks().then(async (tasks): Promise<ITaskSummary | null> => {
149-
if (tasks.filter(t => t._id === task._id).length) {
149+
if (tasks.find(t => t._id === task._id)) {
150150
// Check that the task isn't busy and if it is, wait for it
151151
const busyTasks = await this.taskService.getBusyTasks();
152-
if (busyTasks.filter(t => t._id === task._id).length) {
152+
if (busyTasks.find(t => t._id === task._id)) {
153153
taskStarted = true;
154154
return inactivePromise;
155155
}

src/vs/workbench/contrib/debug/browser/variablesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class VariablesView extends ViewPane {
8181
const scopes = await stackFrame.getScopes();
8282
// Expand the first scope if it is not expensive and if there is no expansion state (all are collapsed)
8383
if (scopes.every(s => this.tree.getNode(s).collapsed) && scopes.length > 0) {
84-
const toExpand = scopes.filter(s => !s.expensive).shift();
84+
const toExpand = scopes.find(s => !s.expensive);
8585
if (toExpand) {
8686
this.tree.expand(toExpand);
8787
}

src/vs/workbench/contrib/debug/common/debugModel.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ export class DebugModel implements IDebugModel {
873873

874874
getSession(sessionId: string | undefined, includeInactive = false): IDebugSession | undefined {
875875
if (sessionId) {
876-
return this.getSessions(includeInactive).filter(s => s.getId() === sessionId).pop();
876+
return this.getSessions(includeInactive).find(s => s.getId() === sessionId);
877877
}
878878
return undefined;
879879
}
@@ -924,15 +924,15 @@ export class DebugModel implements IDebugModel {
924924
}
925925

926926
rawUpdate(data: IRawModelUpdate): void {
927-
let session = this.sessions.filter(p => p.getId() === data.sessionId).pop();
927+
let session = this.sessions.find(p => p.getId() === data.sessionId);
928928
if (session) {
929929
session.rawUpdate(data);
930930
this._onDidChangeCallStack.fire(undefined);
931931
}
932932
}
933933

934934
clearThreads(id: string, removeThreads: boolean, reference: number | undefined = undefined): void {
935-
const session = this.sessions.filter(p => p.getId() === id).pop();
935+
const session = this.sessions.find(p => p.getId() === id);
936936
this.schedulers.forEach(scheduler => scheduler.dispose());
937937
this.schedulers.clear();
938938

@@ -957,8 +957,6 @@ export class DebugModel implements IDebugModel {
957957
for (let i = 1; i < stale.length && !bottomOfCallStackChanged; i++) {
958958
bottomOfCallStackChanged = !stale[i].equals(current[i]);
959959
}
960-
console.log('bottom of call stack changed');
961-
console.log(bottomOfCallStackChanged);
962960

963961
if (bottomOfCallStackChanged) {
964962
this._onDidChangeCallStack.fire();
@@ -1178,7 +1176,7 @@ export class DebugModel implements IDebugModel {
11781176
}
11791177

11801178
renameFunctionBreakpoint(id: string, name: string): void {
1181-
const functionBreakpoint = this.functionBreakpoints.filter(fbp => fbp.getId() === id).pop();
1179+
const functionBreakpoint = this.functionBreakpoints.find(fbp => fbp.getId() === id);
11821180
if (functionBreakpoint) {
11831181
functionBreakpoint.name = name;
11841182
this._onDidChangeBreakpoints.fire({ changed: [functionBreakpoint], sessionOnly: false });
@@ -1241,7 +1239,7 @@ export class DebugModel implements IDebugModel {
12411239
}
12421240

12431241
moveWatchExpression(id: string, position: number): void {
1244-
const we = this.watchExpressions.filter(we => we.getId() === id).pop();
1242+
const we = this.watchExpressions.find(we => we.getId() === id);
12451243
if (we) {
12461244
this.watchExpressions = this.watchExpressions.filter(we => we.getId() !== id);
12471245
this.watchExpressions = this.watchExpressions.slice(0, position).concat(we, this.watchExpressions.slice(position));

0 commit comments

Comments
 (0)