From 0a3b4bd9134f434a1cc262dc8a60c383d14a0b18 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Wed, 30 Jun 2021 16:28:04 -0700 Subject: [PATCH] Don't block on fetchCallStack requests --- .../breakpoints/notebookBreakpoints.ts | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/breakpoints/notebookBreakpoints.ts b/src/vs/workbench/contrib/notebook/browser/contrib/breakpoints/notebookBreakpoints.ts index 76de82bc30e1d..812c044a04d61 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/breakpoints/notebookBreakpoints.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/breakpoints/notebookBreakpoints.ts @@ -10,7 +10,7 @@ import { isEqual } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; import { Registry } from 'vs/platform/registry/common/platform'; import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; -import { IDebugService } from 'vs/workbench/contrib/debug/common/debug'; +import { IDebugService, IThread } from 'vs/workbench/contrib/debug/common/debug'; import { Thread } from 'vs/workbench/contrib/debug/common/debugModel'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CellEditType, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon'; @@ -104,39 +104,49 @@ class NotebookCellPausing extends Disposable implements IWorkbenchContribution { private readonly _pausedCells = new Set(); constructor( - @IDebugService _debugService: IDebugService, + @IDebugService private readonly _debugService: IDebugService, @INotebookService private readonly _notebookService: INotebookService ) { super(); - this._register(_debugService.getModel().onDidChangeCallStack(async () => { - const newPausedCells = new Set(); - for (const session of _debugService.getModel().getSessions()) { - for (const thread of session.getAllThreads()) { - const callStack = thread.getCallStack(); - if (!callStack.length) { - await (thread as Thread).fetchCallStack(); - } + this._register(_debugService.getModel().onDidChangeCallStack(this.onDidChangeCallStack, this)); + } - thread.getCallStack().forEach(sf => { - const parsed = CellUri.parse(sf.source.uri); - if (parsed) { - newPausedCells.add(sf.source.uri.toString()); - this.editIsPaused(sf.source.uri, true); - } - }); + private async onDidChangeCallStack(): Promise { + const newPausedCells = new Set(); + + const updateForThread = (thread: IThread): void => { + thread.getCallStack().forEach(sf => { + const parsed = CellUri.parse(sf.source.uri); + if (parsed) { + newPausedCells.add(sf.source.uri.toString()); + this.editIsPaused(sf.source.uri, true); + } + }); + }; + + const promises: Promise[] = []; + for (const session of this._debugService.getModel().getSessions()) { + for (const thread of session.getAllThreads()) { + const callStack = thread.getCallStack(); + if (callStack.length) { + updateForThread(thread); + } else { + promises.push( + (thread as Thread).fetchCallStack().then(() => updateForThread(thread))); } } + } - for (const uri of this._pausedCells) { - if (!newPausedCells.has(uri)) { - this.editIsPaused(URI.parse(uri), false); - this._pausedCells.delete(uri); - } + await Promise.all(promises); + for (const uri of this._pausedCells) { + if (!newPausedCells.has(uri)) { + this.editIsPaused(URI.parse(uri), false); + this._pausedCells.delete(uri); } + } - newPausedCells.forEach(cell => this._pausedCells.add(cell)); - })); + newPausedCells.forEach(cell => this._pausedCells.add(cell)); } private editIsPaused(cellUri: URI, isPaused: boolean) {