提交 3cc2460c 编写于 作者: I isidor

debug: more async await

上级 460ef3a4
......@@ -718,8 +718,7 @@ export class DebugSession implements IDebugSession {
// Send all breakpoints
try {
await this.debugService.sendAllBreakpoints(this);
await sendConfigurationDone();
} catch {
} finally {
await sendConfigurationDone();
}
await this.fetchThreads();
......
......@@ -228,25 +228,23 @@ export class RawDebugSession implements IDisposable {
/**
* Starts the underlying debug adapter and tracks the session time for telemetry.
*/
start(): Promise<void> {
async start(): Promise<void> {
if (!this.debugAdapter) {
return Promise.reject(new Error('no debug adapter'));
}
return this.debugAdapter.startSession().then(() => {
this.startTime = new Date().getTime();
}, err => {
return Promise.reject(err);
});
await this.debugAdapter.startSession();
this.startTime = new Date().getTime();
}
/**
* Send client capabilities to the debug adapter and receive DA capabilities in return.
*/
initialize(args: DebugProtocol.InitializeRequestArguments): Promise<DebugProtocol.InitializeResponse> {
return this.send('initialize', args).then((response: DebugProtocol.InitializeResponse) => {
this.mergeCapabilities(response.body);
return response;
});
async initialize(args: DebugProtocol.InitializeRequestArguments): Promise<DebugProtocol.InitializeResponse> {
const response = await this.send('initialize', args);
this.mergeCapabilities(response.body);
return response;
}
/**
......@@ -258,11 +256,11 @@ export class RawDebugSession implements IDisposable {
//---- DAP requests
launchOrAttach(config: IConfig): Promise<DebugProtocol.Response> {
return this.send(config.request, config).then(response => {
this.mergeCapabilities(response.body);
return response;
});
async launchOrAttach(config: IConfig): Promise<DebugProtocol.Response> {
const response = await this.send(config.request, config);
this.mergeCapabilities(response.body);
return response;
}
/**
......@@ -286,35 +284,32 @@ export class RawDebugSession implements IDisposable {
return Promise.reject(new Error('restart not supported'));
}
next(args: DebugProtocol.NextArguments): Promise<DebugProtocol.NextResponse> {
return this.send('next', args).then(response => {
this.fireSimulatedContinuedEvent(args.threadId);
return response;
});
async next(args: DebugProtocol.NextArguments): Promise<DebugProtocol.NextResponse> {
const response = await this.send('next', args);
this.fireSimulatedContinuedEvent(args.threadId);
return response;
}
stepIn(args: DebugProtocol.StepInArguments): Promise<DebugProtocol.StepInResponse> {
return this.send('stepIn', args).then(response => {
this.fireSimulatedContinuedEvent(args.threadId);
return response;
});
async stepIn(args: DebugProtocol.StepInArguments): Promise<DebugProtocol.StepInResponse> {
const response = await this.send('stepIn', args);
this.fireSimulatedContinuedEvent(args.threadId);
return response;
}
stepOut(args: DebugProtocol.StepOutArguments): Promise<DebugProtocol.StepOutResponse> {
return this.send('stepOut', args).then(response => {
this.fireSimulatedContinuedEvent(args.threadId);
return response;
});
async stepOut(args: DebugProtocol.StepOutArguments): Promise<DebugProtocol.StepOutResponse> {
const response = await this.send('stepOut', args);
this.fireSimulatedContinuedEvent(args.threadId);
return response;
}
continue(args: DebugProtocol.ContinueArguments): Promise<DebugProtocol.ContinueResponse> {
return this.send<DebugProtocol.ContinueResponse>('continue', args).then(response => {
if (response && response.body && response.body.allThreadsContinued !== undefined) {
this.allThreadsContinued = response.body.allThreadsContinued;
}
this.fireSimulatedContinuedEvent(args.threadId, this.allThreadsContinued);
return response;
});
async continue(args: DebugProtocol.ContinueArguments): Promise<DebugProtocol.ContinueResponse> {
const response = await this.send<DebugProtocol.ContinueResponse>('continue', args);
if (response && response.body && response.body.allThreadsContinued !== undefined) {
this.allThreadsContinued = response.body.allThreadsContinued;
}
this.fireSimulatedContinuedEvent(args.threadId, this.allThreadsContinued);
return response;
}
pause(args: DebugProtocol.PauseArguments): Promise<DebugProtocol.PauseResponse> {
......@@ -335,12 +330,11 @@ export class RawDebugSession implements IDisposable {
return Promise.reject(new Error('setVariable not supported'));
}
restartFrame(args: DebugProtocol.RestartFrameArguments, threadId: number): Promise<DebugProtocol.RestartFrameResponse> {
async restartFrame(args: DebugProtocol.RestartFrameArguments, threadId: number): Promise<DebugProtocol.RestartFrameResponse> {
if (this.capabilities.supportsRestartFrame) {
return this.send('restartFrame', args).then(response => {
this.fireSimulatedContinuedEvent(threadId);
return response;
});
const response = await this.send('restartFrame', args);
this.fireSimulatedContinuedEvent(threadId);
return response;
}
return Promise.reject(new Error('restartFrame not supported'));
}
......@@ -433,26 +427,24 @@ export class RawDebugSession implements IDisposable {
return this.send<DebugProtocol.EvaluateResponse>('evaluate', args);
}
stepBack(args: DebugProtocol.StepBackArguments): Promise<DebugProtocol.StepBackResponse> {
async stepBack(args: DebugProtocol.StepBackArguments): Promise<DebugProtocol.StepBackResponse> {
if (this.capabilities.supportsStepBack) {
return this.send('stepBack', args).then(response => {
if (response.body === undefined) { // TODO@AW why this check?
this.fireSimulatedContinuedEvent(args.threadId);
}
return response;
});
const response = await this.send('stepBack', args);
if (response.body === undefined) { // TODO@AW why this check?
this.fireSimulatedContinuedEvent(args.threadId);
}
return response;
}
return Promise.reject(new Error('stepBack not supported'));
}
reverseContinue(args: DebugProtocol.ReverseContinueArguments): Promise<DebugProtocol.ReverseContinueResponse> {
async reverseContinue(args: DebugProtocol.ReverseContinueArguments): Promise<DebugProtocol.ReverseContinueResponse> {
if (this.capabilities.supportsStepBack) {
return this.send('reverseContinue', args).then(response => {
if (response.body === undefined) { // TODO@AW why this check?
this.fireSimulatedContinuedEvent(args.threadId);
}
return response;
});
const response = await this.send('reverseContinue', args);
if (response.body === undefined) { // TODO@AW why this check?
this.fireSimulatedContinuedEvent(args.threadId);
}
return response;
}
return Promise.reject(new Error('reverseContinue not supported'));
}
......@@ -464,13 +456,13 @@ export class RawDebugSession implements IDisposable {
return Promise.reject(new Error('gotoTargets is not supported'));
}
goto(args: DebugProtocol.GotoArguments): Promise<DebugProtocol.GotoResponse> {
async goto(args: DebugProtocol.GotoArguments): Promise<DebugProtocol.GotoResponse> {
if (this.capabilities.supportsGotoTargetsRequest) {
return this.send('goto', args).then(res => {
this.fireSimulatedContinuedEvent(args.threadId);
return res;
});
const response = await this.send('goto', args);
this.fireSimulatedContinuedEvent(args.threadId);
return response;
}
return Promise.reject(new Error('goto is not supported'));
}
......@@ -484,36 +476,32 @@ export class RawDebugSession implements IDisposable {
//---- private
private shutdown(error?: Error, restart = false): Promise<any> {
private async shutdown(error?: Error, restart = false): Promise<any> {
if (!this.inShutdown) {
this.inShutdown = true;
if (this.debugAdapter) {
return this.send('disconnect', { restart }, undefined, 500).then(() => {
this.stopAdapter(error);
}, () => {
// ignore error
try {
await this.send('disconnect', { restart }, undefined, 500);
} finally {
this.stopAdapter(error);
});
}
} else {
return this.stopAdapter(error);
}
return this.stopAdapter(error);
}
return Promise.resolve(undefined);
}
private stopAdapter(error?: Error): Promise<any> {
if (this.debugAdapter) {
const da = this.debugAdapter;
this.debugAdapter = null;
return da.stopSession().then(_ => {
private async stopAdapter(error?: Error): Promise<any> {
try {
if (this.debugAdapter) {
const da = this.debugAdapter;
this.debugAdapter = null;
await da.stopSession();
this.debugAdapterStopped = true;
this.fireAdapterExitEvent(error);
}, err => {
this.fireAdapterExitEvent(error);
});
} else {
}
} finally {
this.fireAdapterExitEvent(error);
}
return Promise.resolve(undefined);
}
private fireAdapterExitEvent(error?: Error): void {
......@@ -557,18 +545,19 @@ export class RawDebugSession implements IDisposable {
});
break;
case 'runInTerminal':
dbgr.runInTerminal(request.arguments as DebugProtocol.RunInTerminalRequestArguments).then(shellProcessId => {
try {
const shellProcessId = await dbgr.runInTerminal(request.arguments as DebugProtocol.RunInTerminalRequestArguments);
const resp = response as DebugProtocol.RunInTerminalResponse;
resp.body = {};
if (typeof shellProcessId === 'number') {
resp.body.shellProcessId = shellProcessId;
}
safeSendResponse(resp);
}, err => {
} catch (err) {
response.success = false;
response.message = err.message;
safeSendResponse(response);
});
}
break;
default:
response.success = false;
......
......@@ -24,7 +24,6 @@ import { IAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService';
import { IAsyncDataSource, ITreeMouseEvent, ITreeContextMenuEvent, ITreeDragAndDrop, ITreeDragOverReaction } from 'vs/base/browser/ui/tree/tree';
import { IDragAndDropData } from 'vs/base/browser/dnd';
import { onUnexpectedError } from 'vs/base/common/errors';
import { ElementsDragAndDropData } from 'vs/base/browser/ui/list/listView';
import { FuzzyScore } from 'vs/base/common/filters';
import { IHighlight } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
......@@ -71,7 +70,7 @@ export class WatchExpressionsView extends ViewletPanel {
dnd: new WatchExpressionsDragAndDrop(this.debugService),
});
this.tree.setInput(this.debugService).then(undefined, onUnexpectedError);
this.tree.setInput(this.debugService);
CONTEXT_WATCH_EXPRESSIONS_FOCUSED.bindTo(this.tree.contextKeyService);
if (this.toolbar) {
......
......@@ -114,13 +114,16 @@ export class ExpressionContainer implements IExpressionContainer {
return !!this.reference && this.reference > 0;
}
private fetchVariables(start: number | undefined, count: number | undefined, filter: 'indexed' | 'named' | undefined): Promise<Variable[]> {
return this.session!.variables(this.reference || 0, this.threadId, filter, start, count).then(response => {
private async fetchVariables(start: number | undefined, count: number | undefined, filter: 'indexed' | 'named' | undefined): Promise<Variable[]> {
try {
const response = await this.session!.variables(this.reference || 0, this.threadId, filter, start, count);
return response && response.body && response.body.variables
? distinct(response.body.variables.filter(v => !!v && isString(v.name)), (v: DebugProtocol.Variable) => v.name).map((v: DebugProtocol.Variable) =>
new Variable(this.session, this.threadId, this, v.variablesReference, v.name, v.evaluateName, v.value, v.namedVariables, v.indexedVariables, v.presentationHint, v.type))
: [];
}, (e: Error) => [new Variable(this.session, this.threadId, this, 0, e.message, e.message, '', 0, 0, { kind: 'virtual' }, undefined, false)]);
} catch (e) {
return [new Variable(this.session, this.threadId, this, 0, e.message, e.message, '', 0, 0, { kind: 'virtual' }, undefined, false)];
}
}
// The adapter explicitly sents the children count of an expression only if there are lots of children which should be chunked.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册