From 3fc780dc7caf63ffd23ed1664cdfe17029f2d28d Mon Sep 17 00:00:00 2001 From: isidor Date: Wed, 16 Oct 2019 11:27:25 +0200 Subject: [PATCH] debug more async/await --- .../contrib/debug/browser/breakpointsView.ts | 22 +++++----- .../contrib/debug/common/debugModel.ts | 43 +++++++++---------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/breakpointsView.ts b/src/vs/workbench/contrib/debug/browser/breakpointsView.ts index 624002135be..71f282b932f 100644 --- a/src/vs/workbench/contrib/debug/browser/breakpointsView.ts +++ b/src/vs/workbench/contrib/debug/browser/breakpointsView.ts @@ -161,21 +161,19 @@ export class BreakpointsView extends ViewletPanel { const breakpointType = element instanceof Breakpoint && element.logMessage ? nls.localize('Logpoint', "Logpoint") : nls.localize('Breakpoint', "Breakpoint"); if (element instanceof Breakpoint || element instanceof FunctionBreakpoint) { - actions.push(new Action('workbench.action.debug.openEditorAndEditBreakpoint', nls.localize('editBreakpoint', "Edit {0}...", breakpointType), '', true, () => { + actions.push(new Action('workbench.action.debug.openEditorAndEditBreakpoint', nls.localize('editBreakpoint', "Edit {0}...", breakpointType), '', true, async () => { if (element instanceof Breakpoint) { - return openBreakpointSource(element, false, false, this.debugService, this.editorService).then(editor => { - if (editor) { - const codeEditor = editor.getControl(); - if (isCodeEditor(codeEditor)) { - codeEditor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(element.lineNumber, element.column); - } + const editor = await openBreakpointSource(element, false, false, this.debugService, this.editorService); + if (editor) { + const codeEditor = editor.getControl(); + if (isCodeEditor(codeEditor)) { + codeEditor.getContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID).showBreakpointWidget(element.lineNumber, element.column); } - }); + } + } else { + this.debugService.getViewModel().setSelectedFunctionBreakpoint(element); + this.onBreakpointsChange(); } - - this.debugService.getViewModel().setSelectedFunctionBreakpoint(element); - this.onBreakpointsChange(); - return Promise.resolve(undefined); })); actions.push(new Separator()); } diff --git a/src/vs/workbench/contrib/debug/common/debugModel.ts b/src/vs/workbench/contrib/debug/common/debugModel.ts index 7761a20f4af..2dc46ce56f9 100644 --- a/src/vs/workbench/contrib/debug/common/debugModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugModel.ts @@ -316,18 +316,17 @@ export class StackFrame implements IStackFrame { return (from > 0 ? '...' : '') + this.source.uri.path.substr(from); } - getMostSpecificScopes(range: IRange): Promise { - return this.getScopes().then(scopes => { - scopes = scopes.filter(s => !s.expensive); - const haveRangeInfo = scopes.some(s => !!s.range); - if (!haveRangeInfo) { - return scopes; - } + async getMostSpecificScopes(range: IRange): Promise { + const scopes = await this.getScopes(); + const nonExpensiveScopes = scopes.filter(s => !s.expensive); + const haveRangeInfo = nonExpensiveScopes.some(s => !!s.range); + if (!haveRangeInfo) { + return nonExpensiveScopes; + } - const scopesContainingRange = scopes.filter(scope => scope.range && Range.containsRange(scope.range, range)) - .sort((first, second) => (first.range!.endLineNumber - first.range!.startLineNumber) - (second.range!.endLineNumber - second.range!.startLineNumber)); - return scopesContainingRange.length ? scopesContainingRange : scopes; - }); + const scopesContainingRange = nonExpensiveScopes.filter(scope => scope.range && Range.containsRange(scope.range, range)) + .sort((first, second) => (first.range!.endLineNumber - first.range!.startLineNumber) - (second.range!.endLineNumber - second.range!.startLineNumber)); + return scopesContainingRange.length ? scopesContainingRange : nonExpensiveScopes; } restart(): Promise { @@ -404,23 +403,21 @@ export class Thread implements IThread { * Only fetches the first stack frame for performance reasons. Calling this method consecutive times * gets the remainder of the call stack. */ - fetchCallStack(levels = 20): Promise { - if (!this.stopped) { - return Promise.resolve(undefined); - } - - const start = this.callStack.length; - return this.getCallStackImpl(start, levels).then(callStack => { + async fetchCallStack(levels = 20): Promise { + if (this.stopped) { + const start = this.callStack.length; + const callStack = await this.getCallStackImpl(start, levels); if (start < this.callStack.length) { // Set the stack frames for exact position we requested. To make sure no concurrent requests create duplicate stack frames #30660 this.callStack.splice(start, this.callStack.length - start); } this.callStack = this.callStack.concat(callStack || []); - }); + } } - private getCallStackImpl(startFrame: number, levels: number): Promise { - return this.session.stackTrace(this.threadId, startFrame, levels).then(response => { + private async getCallStackImpl(startFrame: number, levels: number): Promise { + try { + const response = await this.session.stackTrace(this.threadId, startFrame, levels); if (!response || !response.body) { return []; } @@ -439,13 +436,13 @@ export class Thread implements IThread { rsf.endColumn || rsf.column ), startFrame + index); }); - }, (err: Error) => { + } catch (err) { if (this.stoppedDetails) { this.stoppedDetails.framesErrorMessage = err.message; } return []; - }); + } } /** -- GitLab