From c7e79b66aaddda013933f0bc25afc93bb8a34b18 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Sun, 4 Jun 2023 19:36:21 +0900 Subject: [PATCH] Add the ability to set to change a value of the variable Closes ruby/vscode-rdbg#53 --- package.json | 10 ++++++++++ src/extension.ts | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/package.json b/package.json index 0c33c660..0d585557 100644 --- a/package.json +++ b/package.json @@ -300,6 +300,10 @@ { "command": "rdbg.inspector.disableTraceClanguageCall", "title": "✓ Trace c_call / c_return" + }, + { + "command": "rdbg.setVariableValue", + "title": "Set Value" } ], "menus": { @@ -370,6 +374,12 @@ "command": "rdbg.inspector.copyLog", "when": "view == rdbg.inspector" } + ], + "debug/variables/context": [ + { + "command": "rdbg.setVariableValue", + "when": "debugType == 'rdbg'" + } ] } }, diff --git a/src/extension.ts b/src/extension.ts index 959bc14c..32ad63f3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -145,6 +145,28 @@ export function activate(context: vscode.ExtensionContext) { } } + context.subscriptions.push( + vscode.commands.registerCommand("rdbg.setVariableValue", async(variable) => { + const session = vscode.debug.activeDebugSession; + const value = await vscode.window.showInputBox({ + title: "Enter a value of the variable", + }); + if (value === undefined || session === undefined) { + return; + } + const name = variable.variable.name; + const args: DebugProtocol.EvaluateArguments = { + expression: `,eval ${name}=${value}`, + context: "repl" + }; + try { + await session.customRequest("evaluate", args); + } catch (err) { + vscode.window.showErrorMessage(`Failed to set a value: ${err}`); + } + }) + ); + const disp = registerInspectorView(DAPTrackQueue, adapterDescriptorFactory); context.subscriptions.concat(disp); }