Skip to content

Commit d4abfac

Browse files
committed
change variable value in debugging
1 parent 22bcb4e commit d4abfac

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/debug/debugSession.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
105105
...response.body,
106106
supportsConfigurationDoneRequest: true,
107107
supportsEvaluateForHovers: true,
108-
supportsSetVariable: false, // TODO
108+
supportsSetVariable: true,
109109
supportsConditionalBreakpoints: false, // TODO
110110
supportsStepBack: false,
111111
};
@@ -505,4 +505,29 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
505505
}
506506
this.sendResponse(response);
507507
}
508+
509+
protected async setVariableRequest(
510+
response: DebugProtocol.SetVariableResponse,
511+
args: DebugProtocol.SetVariableArguments
512+
): Promise<void> {
513+
const { value, name, variablesReference } = args;
514+
let property = null;
515+
if (this._contexts.has(variablesReference)) {
516+
// VS Code is requesting the variables for a SCOPE, so we have to do a context_get
517+
const context = this._contexts.get(variablesReference);
518+
const properties = await context.getProperties();
519+
property = properties.find(el => el.name === name);
520+
} else if (this._properties.has(variablesReference)) {
521+
// VS Code is requesting the subelements for a variable, so we have to do a property_get
522+
property = this._properties.get(variablesReference);
523+
}
524+
property.value = value;
525+
await this._connection.sendPropertySetCommand(property);
526+
527+
response.body = {
528+
value: args.value,
529+
variablesReference: args.variablesReference,
530+
};
531+
this.sendResponse(response);
532+
}
508533
}

src/debug/xdebugConnection.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,22 @@ export class PropertyGetResponse extends Response {
497497
}
498498
}
499499

500+
/** The response to a property_set command */
501+
export class PropertySetResponse extends Response {
502+
/** the children of the given property */
503+
public children: Property[];
504+
/**
505+
* @param {XMLDocument} document
506+
* @param {Property} property
507+
*/
508+
public constructor(document: XMLDocument, property: Property) {
509+
super(document, property.context.stackFrame.connection);
510+
// this.children = Array.from(document.documentElement.firstChild.childNodes).map(
511+
// (propertyNode: Element): Property => new Property(propertyNode, property.context)
512+
// );
513+
}
514+
}
515+
500516
/**
501517
* class for properties returned from eval commands.
502518
* These don't have a full name or an ID, but have all children already inlined.
@@ -822,6 +838,18 @@ export class Connection extends DbgpConnection {
822838
);
823839
}
824840

841+
/** Sends a property_get command */
842+
public async sendPropertySetCommand(property: Property): Promise<PropertySetResponse> {
843+
const value = Buffer.from(property.value).toString("base64");
844+
return new PropertySetResponse(
845+
await this._enqueueCommand(
846+
"property_set",
847+
`-d ${property.context.stackFrame.level} -n ${property.fullName} -- ${value}`
848+
),
849+
property
850+
);
851+
}
852+
825853
// ------------------------------- eval -----------------------------------------
826854

827855
/** sends an eval command */

0 commit comments

Comments
 (0)