Skip to content

Commit

Permalink
support debug set expression
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Jun 29, 2023
1 parent 445c99f commit 1cc72a3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
34 changes: 18 additions & 16 deletions src/debugger/base/EmmyDebugData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,41 @@ export class EmmyVariable implements IEmmyStackNode {
private parent?: EmmyVariable,
) {
let value = this.data.value;
let presentationHint: DebugProtocol.VariablePresentationHint = {
kind: 'property',
attributes: []
};
// vscode not implement this feature
// let presentationHint: DebugProtocol.VariablePresentationHint = {
// kind: 'property',
// attributes: []
// };
switch (this.data.valueType) {
case proto.ValueType.TSTRING:
value = `"${this.data.value}"`;
presentationHint.attributes?.push('rawString');
break;
case proto.ValueType.TFUNCTION:
presentationHint.kind = 'method';
break;
// presentationHint.attributes?.push('rawString');
// break;
// case proto.ValueType.TFUNCTION:
// presentationHint.kind = 'method';
// break;
}
let name = this.data.name;
switch (this.data.nameType) {
case proto.ValueType.TSTRING:
if (name.startsWith("_")) {
presentationHint.attributes?.push('private');
}
else {
presentationHint.attributes?.push('public');
}
// if (name.startsWith("_")) {
// presentationHint.attributes?.push('private');
// }
// else {
// presentationHint.attributes?.push('public');
// }

break;
case proto.ValueType.TNUMBER:
name = `[${name}]`;
presentationHint.kind = 'data'
// presentationHint.kind = 'data'
break;
default:
name = `[${name}]`;
break;
}
this.variable = { name, value, variablesReference: 0, presentationHint };
this.variable = { name, value, variablesReference: 0 };
}

toVariable(ctx: IEmmyStackContext): DebugProtocol.Variable {
Expand Down
2 changes: 2 additions & 0 deletions src/debugger/base/EmmyDebugProto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export interface IEvalReq extends IMessage {
stackLevel: number;
depth: number;
cacheId: number;
value?: string;
setValue?: boolean;
}

export interface IEvalRsp {
Expand Down
45 changes: 44 additions & 1 deletion src/debugger/base/EmmyDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class EmmyDebugSession extends DebugSession implements IEmmyStackContext
supportTerminateDebuggee: true,
supportsLogPoints: true,
supportsHitConditionalBreakpoints: true,
// supports: true,
supportsSetExpression: true,
// supportsDelayedStackTraceLoading: true,
// supportsCompletionsRequest: true
};
Expand Down Expand Up @@ -232,6 +232,29 @@ export class EmmyDebugSession extends DebugSession implements IEmmyStackContext
});
}

async setEval(expr: string, value: string, cacheId: number, depth: number = 1, stackLevel = -1): Promise<proto.IEvalRsp> {
const req: proto.IEvalReq = {
cmd: proto.MessageCMD.EvalReq,
seq: this.evalIdCount++,
stackLevel: stackLevel >= 0 ? stackLevel : this.currentFrameId,
expr,
depth,
cacheId,
value,
setValue: true,
};
this.sendMessage(req);
return new Promise<proto.IEvalRsp>((resolve, reject) => {
const listener = (msg: proto.IEvalRsp) => {
if (msg.seq === req.seq) {
this.removeListener('onEvalRsp', listener);
resolve(msg);
}
};
this.on('onEvalRsp', listener);
});
}

protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments): void {
const source = args.source;
const bpsProto: proto.IBreakPoint[] = [];
Expand Down Expand Up @@ -262,6 +285,26 @@ export class EmmyDebugSession extends DebugSession implements IEmmyStackContext
this.sendResponse(response);
}

protected async setExpressionRequest(response: DebugProtocol.SetExpressionResponse, args: DebugProtocol.SetExpressionArguments, request?: DebugProtocol.Request): Promise<void> {
const evalResp = await this.setEval(args.expression, args.value,0, 1, args.frameId);
if (evalResp.success) {
const emmyVar = new EmmyVariable(evalResp.value);
const variable = emmyVar.toVariable(this);
response.body = {
value: variable.value,
type: variable.type,
variablesReference: variable.variablesReference
};
}
else {
response.body = {
value: evalResp.error,
type: 'string',
variablesReference: 0
};
}
this.sendResponse(response);
}
// protected completionsRequest(response: DebugProtocol.CompletionsResponse, args: DebugProtocol.CompletionsArguments, request?: DebugProtocol.Request): void {

// }
Expand Down

0 comments on commit 1cc72a3

Please sign in to comment.