From 99445b688d38337fbb8442c5dd463cfba44d7dbf Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Fri, 22 Mar 2024 12:10:05 +0100 Subject: [PATCH] Add debug var context menu view as hex/bin --- Makefile | 2 +- package.json | 14 ++++++++++++++ src/Extension.hx | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 050fabc..241a810 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ cleanup: /bin/find . -name *.map | xargs rm -rf package: cleanup #npm install vsce -g - haxe -cp src -lib vscode -lib vshaxe -D js-es=6 -js extension.js Extension + haxe -cp src -lib vscode -lib vshaxe -lib vscode-debugadapter -D js-es=6 -js extension.js Extension vsce package # to get token : diff --git a/package.json b/package.json index e753658..ada5eab 100644 --- a/package.json +++ b/package.json @@ -158,6 +158,20 @@ } ] } + ], + "menus": { + "debug/variables/context": [ + { + "command": "hldebug.var.formatInt", + "when": "debugType == 'hl'" + } + ] + }, + "commands": [ + { + "command": "hldebug.var.formatInt", + "title": "View as Hex & Bin" + } ] }, "__metadata": { diff --git a/src/Extension.hx b/src/Extension.hx index 89f256d..6c81d1f 100644 --- a/src/Extension.hx +++ b/src/Extension.hx @@ -5,6 +5,7 @@ class Extension { @:expose("activate") static function main(context:ExtensionContext) { Vscode.debug.registerDebugConfigurationProvider("hl", {resolveDebugConfiguration: resolveDebugConfiguration}); + context.subscriptions.push(Vscode.commands.registerCommand("hldebug.var.formatInt", formatInt)); } static function resolveDebugConfiguration(folder:Null, config:DebugConfiguration, @@ -57,4 +58,32 @@ class Extension { }); }); } + + inline static function toString(value:Int, base:Int):String { + #if js + return untyped value.toString(base); + #else + throw "Not implemented"; + #end + } + + static function formatInt(args:VariableContextCommandArg) { + var i = Std.parseInt(args.variable.value); + if (i == null) + return; + Vscode.window.showInformationMessage(args.variable.name + "(" + i + ") = 0x" + toString(i,16) + " = 0b" + toString(i,2)); + } +} + +typedef Container = { + var name : String; + var variablesReference : Int; + var ?expensive : Bool; + var ?value : String; +} + +typedef VariableContextCommandArg = { + var sessionId : String; + var container : Container; + var variable : vscode.debugProtocol.DebugProtocol.Variable; }