Skip to content

Commit a47a516

Browse files
committed
added ability to set a variable
1 parent eb9474c commit a47a516

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/client/debugger/Main.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class PythonDebugger extends DebugSession {
5757
response.body.supportsConfigurationDoneRequest = true;
5858
response.body.supportsEvaluateForHovers = false;
5959
response.body.supportsFunctionBreakpoints = false;
60+
response.body.supportsSetVariable = true;
6061
response.body.exceptionBreakpointFilters = [
6162
{
6263
label: "All Exceptions",
@@ -611,6 +612,31 @@ export class PythonDebugger extends DebugSession {
611612
this.stopDebugServer();
612613
this.sendResponse(response);
613614
}
615+
protected setVariableRequest(response: DebugProtocol.SetVariableResponse, args: DebugProtocol.SetVariableArguments) {
616+
let variable = this._variableHandles.get(args.variablesReference).variables.find(v => v.ChildName === args.name);
617+
if (!variable) {
618+
return this.sendErrorResponse(response, 2000, 'Variable reference not found');
619+
}
620+
this.pythonProcess.ExecuteText(`${args.name} = ${args.value}`, PythonEvaluationResultReprKind.Normal, variable.Frame).then(result => {
621+
return this.pythonProcess.ExecuteText(args.name, PythonEvaluationResultReprKind.Normal, variable.Frame).then(result => {
622+
let variablesReference = 0;
623+
// If this value can be expanded, then create a vars ref for user to expand it
624+
if (result.IsExpandable) {
625+
const parentVariable: IDebugVariable = {
626+
variables: [result],
627+
evaluateChildren: true
628+
};
629+
variablesReference = this._variableHandles.create(parentVariable);
630+
}
631+
response.body = {
632+
value: result.StringRepr
633+
};
634+
this.sendResponse(response);
635+
});
636+
}).catch(error => this.sendErrorResponse(response, 2000, error));
637+
}
638+
// protected stepInTargetsRequest(response: DebugProtocol.StepInTargetsResponse, args: DebugProtocol.StepInTargetsArguments): void;
639+
// protected gotoTargetsRequest(response: DebugProtocol.GotoTargetsResponse, args: DebugProtocol.GotoTargetsArguments): void;
614640
}
615641

616642
DebugSession.run(PythonDebugger);

0 commit comments

Comments
 (0)