Skip to content

Commit 3fc780d

Browse files
committed
debug more async/await
1 parent 042caca commit 3fc780d

2 files changed

Lines changed: 30 additions & 35 deletions

File tree

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,19 @@ export class BreakpointsView extends ViewletPanel {
161161

162162
const breakpointType = element instanceof Breakpoint && element.logMessage ? nls.localize('Logpoint', "Logpoint") : nls.localize('Breakpoint', "Breakpoint");
163163
if (element instanceof Breakpoint || element instanceof FunctionBreakpoint) {
164-
actions.push(new Action('workbench.action.debug.openEditorAndEditBreakpoint', nls.localize('editBreakpoint', "Edit {0}...", breakpointType), '', true, () => {
164+
actions.push(new Action('workbench.action.debug.openEditorAndEditBreakpoint', nls.localize('editBreakpoint', "Edit {0}...", breakpointType), '', true, async () => {
165165
if (element instanceof Breakpoint) {
166-
return openBreakpointSource(element, false, false, this.debugService, this.editorService).then(editor => {
167-
if (editor) {
168-
const codeEditor = editor.getControl();
169-
if (isCodeEditor(codeEditor)) {
170-
codeEditor.getContribution<IBreakpointEditorContribution>(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(element.lineNumber, element.column);
171-
}
166+
const editor = await openBreakpointSource(element, false, false, this.debugService, this.editorService);
167+
if (editor) {
168+
const codeEditor = editor.getControl();
169+
if (isCodeEditor(codeEditor)) {
170+
codeEditor.getContribution<IBreakpointEditorContribution>(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(element.lineNumber, element.column);
172171
}
173-
});
172+
}
173+
} else {
174+
this.debugService.getViewModel().setSelectedFunctionBreakpoint(element);
175+
this.onBreakpointsChange();
174176
}
175-
176-
this.debugService.getViewModel().setSelectedFunctionBreakpoint(element);
177-
this.onBreakpointsChange();
178-
return Promise.resolve(undefined);
179177
}));
180178
actions.push(new Separator());
181179
}

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,17 @@ export class StackFrame implements IStackFrame {
316316
return (from > 0 ? '...' : '') + this.source.uri.path.substr(from);
317317
}
318318

319-
getMostSpecificScopes(range: IRange): Promise<IScope[]> {
320-
return this.getScopes().then(scopes => {
321-
scopes = scopes.filter(s => !s.expensive);
322-
const haveRangeInfo = scopes.some(s => !!s.range);
323-
if (!haveRangeInfo) {
324-
return scopes;
325-
}
319+
async getMostSpecificScopes(range: IRange): Promise<IScope[]> {
320+
const scopes = await this.getScopes();
321+
const nonExpensiveScopes = scopes.filter(s => !s.expensive);
322+
const haveRangeInfo = nonExpensiveScopes.some(s => !!s.range);
323+
if (!haveRangeInfo) {
324+
return nonExpensiveScopes;
325+
}
326326

327-
const scopesContainingRange = scopes.filter(scope => scope.range && Range.containsRange(scope.range, range))
328-
.sort((first, second) => (first.range!.endLineNumber - first.range!.startLineNumber) - (second.range!.endLineNumber - second.range!.startLineNumber));
329-
return scopesContainingRange.length ? scopesContainingRange : scopes;
330-
});
327+
const scopesContainingRange = nonExpensiveScopes.filter(scope => scope.range && Range.containsRange(scope.range, range))
328+
.sort((first, second) => (first.range!.endLineNumber - first.range!.startLineNumber) - (second.range!.endLineNumber - second.range!.startLineNumber));
329+
return scopesContainingRange.length ? scopesContainingRange : nonExpensiveScopes;
331330
}
332331

333332
restart(): Promise<void> {
@@ -404,23 +403,21 @@ export class Thread implements IThread {
404403
* Only fetches the first stack frame for performance reasons. Calling this method consecutive times
405404
* gets the remainder of the call stack.
406405
*/
407-
fetchCallStack(levels = 20): Promise<void> {
408-
if (!this.stopped) {
409-
return Promise.resolve(undefined);
410-
}
411-
412-
const start = this.callStack.length;
413-
return this.getCallStackImpl(start, levels).then(callStack => {
406+
async fetchCallStack(levels = 20): Promise<void> {
407+
if (this.stopped) {
408+
const start = this.callStack.length;
409+
const callStack = await this.getCallStackImpl(start, levels);
414410
if (start < this.callStack.length) {
415411
// Set the stack frames for exact position we requested. To make sure no concurrent requests create duplicate stack frames #30660
416412
this.callStack.splice(start, this.callStack.length - start);
417413
}
418414
this.callStack = this.callStack.concat(callStack || []);
419-
});
415+
}
420416
}
421417

422-
private getCallStackImpl(startFrame: number, levels: number): Promise<IStackFrame[]> {
423-
return this.session.stackTrace(this.threadId, startFrame, levels).then(response => {
418+
private async getCallStackImpl(startFrame: number, levels: number): Promise<IStackFrame[]> {
419+
try {
420+
const response = await this.session.stackTrace(this.threadId, startFrame, levels);
424421
if (!response || !response.body) {
425422
return [];
426423
}
@@ -439,13 +436,13 @@ export class Thread implements IThread {
439436
rsf.endColumn || rsf.column
440437
), startFrame + index);
441438
});
442-
}, (err: Error) => {
439+
} catch (err) {
443440
if (this.stoppedDetails) {
444441
this.stoppedDetails.framesErrorMessage = err.message;
445442
}
446443

447444
return [];
448-
});
445+
}
449446
}
450447

451448
/**

0 commit comments

Comments
 (0)