Skip to content

Commit

Permalink
Don't block on fetchCallStack requests
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jun 30, 2021
1 parent 07a0575 commit 0a3b4bd
Showing 1 changed file with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -104,39 +104,49 @@ class NotebookCellPausing extends Disposable implements IWorkbenchContribution {
private readonly _pausedCells = new Set<string>();

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<string>();
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<void> {
const newPausedCells = new Set<string>();

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<void>[] = [];
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) {
Expand Down

0 comments on commit 0a3b4bd

Please sign in to comment.