diff --git a/.vscodeignore b/.vscodeignore index 3d6b0c0..d88f487 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,7 +1,6 @@ * */** !node_modules/**/* -!adapter.js !bindings.js !CHANGELOG.md !extension.js diff --git a/Makefile b/Makefile index 241a810..37d5b18 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 -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 : diff --git a/package.json b/package.json index c0d4115..a64598c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ { "type": "hl", "label": "HashLink", - "program": "./adapter.js", "runtime": "node", "configurationAttributes": { "launch": { diff --git a/src/Extension.hx b/src/Extension.hx index 6c81d1f..d7e6e6a 100644 --- a/src/Extension.hx +++ b/src/Extension.hx @@ -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, config:DebugConfiguration, @@ -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 { + 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; } diff --git a/src/HLAdapter.hx b/src/HLAdapter.hx index 809daed..8edfe54 100644 --- a/src/HLAdapter.hx +++ b/src/HLAdapter.hx @@ -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; @@ -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; @@ -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")); @@ -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) { @@ -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)); + } + } diff --git a/src/Util.hx b/src/Util.hx new file mode 100644 index 0000000..46fdc97 --- /dev/null +++ b/src/Util.hx @@ -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 + } +}