Skip to content

Commit e9f2720

Browse files
committed
supporting setting values in live watch
1 parent dbc76f2 commit e9f2720

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/views/live-watch/live-watch.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
152152
const refreshCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.refresh', async () => await this.refresh());
153153
const modifyCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.modify', async (node) => await this.handleRenameCommand(node));
154154
const copyCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.copy', async (node) => await this.handleCopyCommand(node));
155+
const setValueCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.setValue', async (node) => {
156+
await this.handleSetValueCommand(node);
157+
});
155158
const addToLiveWatchCommand = vscode.commands.registerCommand('vscode-cmsis-debugger.liveWatch.addToLiveWatchFromTextEditor',
156159
async () => await this.handleAddFromSelectionCommand());
157160
/* omarArm: I am using the same callback function for both watch window and variables view, as they have the same payload structure for now.
@@ -174,6 +177,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
174177
refreshCommand,
175178
modifyCommand,
176179
copyCommand,
180+
setValueCommand,
177181
addToLiveWatchCommand,
178182
addToLiveWatchFromWatchWindowCommand,
179183
addToLiveWatchFromVariablesViewCommand,
@@ -284,6 +288,32 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
284288
return response;
285289
}
286290

291+
private async handleSetValueCommand(node: LiveWatchNode) {
292+
if (!node) {
293+
return;
294+
}
295+
const newValue = await vscode.window.showInputBox({ prompt: 'New Value', value: node.value.result });
296+
if (newValue === undefined) {
297+
return;
298+
}
299+
// VSCode sends setExpression requests for parent nodes, and setVariable requests for child nodes. We can use the presence of parent to determine which request to send.
300+
if (node.parent) {
301+
await this._activeSession?.session.customRequest('setVariable', {
302+
name: node.expression,
303+
value: newValue,
304+
variablesReference: node.parent.value.variablesReference
305+
});
306+
} else {
307+
const frameId = (vscode.debug.activeStackItem as vscode.DebugStackFrame)?.frameId ?? 0;
308+
await this._activeSession?.session.customRequest('setExpression', {
309+
expression: node.expression,
310+
value: newValue,
311+
frameId: frameId
312+
});
313+
}
314+
await this.refresh(node);
315+
}
316+
287317
private async addToRoots(expression: string, parent?: LiveWatchNode) {
288318
// Create a new node with a unique ID and evaluate its value
289319
const newNode: LiveWatchNode = {

0 commit comments

Comments
 (0)