Skip to content

Commit

Permalink
Back to standalone adapter.js for compound launch
Browse files Browse the repository at this point in the history
Support multiple HLAdapter+API instances in the same vscode window (same Extension).
  • Loading branch information
yuxiaomao committed May 30, 2024
1 parent 945c64f commit 7501ee3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*
*/**
!node_modules/**/*
!adapter.js
!bindings.js
!CHANGELOG.md
!extension.js
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ cleanup:
find . -name *.tlog | xargs rm -rf
find . -name *.map | xargs rm -rf
build:
haxe -cp src -lib vscode -lib vshaxe -lib vscode-debugadapter -lib format -lib hscript -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
haxe build.hxml
package: cleanup build
#npm install vsce -g
vsce package
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
{
"type": "hl",
"label": "HashLink",
"program": "./adapter.js",
"runtime": "node",
"configurationAttributes": {
"launch": {
Expand Down
32 changes: 28 additions & 4 deletions src/Extension.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Extension {
static function main(context:ExtensionContext) {
Vscode.debug.registerDebugConfigurationProvider("hl", {resolveDebugConfiguration: resolveDebugConfiguration});
Vscode.debug.registerDebugAdapterDescriptorFactory("hl", {createDebugAdapterDescriptor: createDebugAdapterDescriptor});
context.subscriptions.push(Vscode.commands.registerCommand("hldebug.var.formatInt", args -> HLAdapter.inst?.formatInt(args)));
context.subscriptions.push(Vscode.commands.registerCommand("hldebug.var.formatInt", args -> formatInt(args)));
}

static function resolveDebugConfiguration(folder:Null<WorkspaceFolder>, config:DebugConfiguration,
Expand Down Expand Up @@ -63,8 +63,32 @@ class Extension {

static function createDebugAdapterDescriptor(session: DebugSession, ?executable:DebugAdapterExecutable): ProviderResult<vscode.DebugAdapterDescriptor> {
var config = Vscode.workspace.getConfiguration("hldebug");
HLAdapter.DEBUG = config.get("verbose", false);
var adapter = new HLAdapter(config.get("defaultPort", 6112));
return new vscode.DebugAdapterInlineImplementation(cast adapter);
var isVerbose = config.get("verbose", false);
var defaultPort = config.get("defaultPort", 6112);

/*
// Can be used to communicate with one built-in adapter during execution. Build with -lib format -lib hscript.
if( HLAdapter.inst == null ) {
HLAdapter.DEBUG = isVerbose;
HLAdapter.DEFAULT_PORT = defaultPort;
var adapter = new HLAdapter();
return new vscode.DebugAdapterInlineImplementation(cast adapter);
}
*/

if( executable == null )
Vscode.window.showErrorMessage("No executable specified. Please check your configuration.");
if( isVerbose )
executable.args.push("--verbose");
executable.args.push("--defaultPort");
executable.args.push("" + defaultPort);
return executable;
}

static function formatInt( args:VariableContextCommandArg ) {
var i = Std.parseInt(args.variable.value);
if (i == null)
return;
Vscode.window.showInformationMessage(args.variable.name + "(" + i + ") = 0x" + Utils.toString(i,16) + " = 0b" + Utils.toString(i,2));
}
}
39 changes: 25 additions & 14 deletions src/HLAdapter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HLAdapter extends DebugSession {
static var UID = 0;
public static var inst : HLAdapter;
public static var DEBUG = false;
public static var DEFAULT_PORT : Int = 6112;

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

public function new( defaultPort : Int = 6112 ) {
public function new() {
super();
allowEvalGetters = false;
debugPort = defaultPort;
debugPort = DEFAULT_PORT;
doDebug = true;
threads = new Map();
startTime = haxe.Timer.stamp();
Expand Down Expand Up @@ -1087,7 +1088,28 @@ class HLAdapter extends DebugSession {
// Standalone adapter.js

static function main() {
if( DEBUG ) {
function paramError( msg ) {
Sys.stderr().writeString(msg + "\n");
// Sys.exit(1); // Ignore error
}

var args = Sys.args();
while( args.length > 0 && args[0].charCodeAt(0) == '-'.code ) {
var param = args.shift();
switch( param ) {
case "--verbose":
HLAdapter.DEBUG = true;
case "--defaultPort":
param = args.shift();
var port : Int;
if( param != null && (port = Std.parseInt(param)) != 0 )
HLAdapter.DEFAULT_PORT = port;
paramError("Require defaultPort int value");
default:
paramError("Unsupported parameter " + param);
}
}
if( HLAdapter.DEBUG ) {
js.Node.process.on("uncaughtException", function(e:js.lib.Error) {
if( inst != null ) inst.sendEvent(new OutputEvent("*** ERROR *** " +e.message+"\n"+e.stack, Stderr));
Sys.exit(1);
Expand All @@ -1096,15 +1118,4 @@ class HLAdapter extends DebugSession {
DebugSession.run( HLAdapter );
}

// Communicate with Extension

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

}

0 comments on commit 7501ee3

Please sign in to comment.