Skip to content

Commit

Permalink
Add debug var context menu view as hex/bin
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Mar 22, 2024
1 parent cc855b1 commit 99445b6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
29 changes: 29 additions & 0 deletions src/Extension.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkspaceFolder>, config:DebugConfiguration,
Expand Down Expand Up @@ -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;
}

0 comments on commit 99445b6

Please sign in to comment.