Skip to content

Commit

Permalink
Run HLAdapter with Extension instead of standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Mar 27, 2024
1 parent d4e60ea commit 8176a71
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
1 change: 0 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*
*/**
!node_modules/**/*
!adapter.js
!bindings.js
!CHANGELOG.md
!extension.js
Expand Down
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 -lib vscode-debugadapter -D js-es=6 -js extension.js Extension
haxe -cp src -lib vscode -lib vshaxe -lib vscode-debugadapter -lib format -lib hscript -D js-es=6 -js extension.js Extension
vsce package

# to get token :
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
{
"type": "hl",
"label": "HashLink",
"program": "./adapter.js",
"runtime": "node",
"configurationAttributes": {
"launch": {
Expand Down
31 changes: 4 additions & 27 deletions src/Extension.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ 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));
Vscode.debug.registerDebugAdapterDescriptorFactory("hl", {createDebugAdapterDescriptor: createDebugAdapterDescriptor});
context.subscriptions.push(Vscode.commands.registerCommand("hldebug.var.formatInt", args -> HLAdapter.inst?.formatInt(args)));
}

static function resolveDebugConfiguration(folder:Null<WorkspaceFolder>, config:DebugConfiguration,
Expand Down Expand Up @@ -59,31 +60,7 @@ 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 createDebugAdapterDescriptor(session: DebugSession, ?executable:DebugAdapterExecutable): ProviderResult<vscode.DebugAdapterDescriptor> {
return new vscode.DebugAdapterInlineImplementation(cast new HLAdapter());
}

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;
}
16 changes: 13 additions & 3 deletions src/HLAdapter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum VarValue {
class HLAdapter extends DebugSession {

static var UID = 0;
static var inst : HLAdapter;
public static var inst : HLAdapter;

var proc : ChildProcessObject;
var workspaceDirectory : String;
Expand All @@ -42,7 +42,7 @@ class HLAdapter extends DebugSession {
static var isWindows = Sys.systemName() == "Windows";
static var isMac = Sys.systemName() == "Mac";

function new() {
public function new() {
super();
allowEvalGetters = false;
debugPort = 6112;
Expand All @@ -56,7 +56,6 @@ class HLAdapter extends DebugSession {

override function initializeRequest(response:InitializeResponse, args:InitializeRequestArguments) {


haxe.Log.trace = function(v:Dynamic, ?p:haxe.PosInfos) {
var str = haxe.Log.formatOutput(v, p);
sendEvent(new OutputEvent(Std.int((haxe.Timer.stamp() - startTime)*10) / 10 + "> " + str+"\n"));
Expand Down Expand Up @@ -1052,6 +1051,8 @@ class HLAdapter extends DebugSession {
sendEvent(new OutputEvent(msg+"\n", Stderr));
}

// Standalone adapter.js

static function main() {
if( DEBUG ) {
js.Node.process.on("uncaughtException", function(e:js.lib.Error) {
Expand All @@ -1062,4 +1063,13 @@ class HLAdapter extends DebugSession {
DebugSession.run( HLAdapter );
}

// Communicate with Extension

public function formatInt( args:Util.VariableContextCommandArg ) {
var i = Std.parseInt(args.variable.value);
if (i == null)
return;
Vscode.window.showInformationMessage(args.variable.name + "(" + i + ") = 0x" + Util.toString(i,16) + " = 0b" + Util.toString(i,2));
}

}
21 changes: 21 additions & 0 deletions src/Util.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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;
}

class Util {

inline public static function toString(value:Int, base:Int):String {
#if js
return untyped value.toString(base);
#end
}
}

0 comments on commit 8176a71

Please sign in to comment.