Skip to content

Commit

Permalink
Sort of fixed multi session startup issue
Browse files Browse the repository at this point in the history
- extension.ts now uses promises
  • Loading branch information
Serena committed Jun 11, 2024
1 parent 513fda8 commit 50e7572
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 147 deletions.
143 changes: 55 additions & 88 deletions cider-dap/calyxDebug/built/extension.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var vscode = require("vscode");
var cp = require("child_process");
Expand All @@ -44,36 +8,29 @@ var programName = null; // Store the program name
// Create output channel
var outputChannel = vscode.window.createOutputChannel("Cider dap");
function logToPanel(message) {
console.log("inside logPanel");
//console.log("inside logPanel");
outputChannel.appendLine(message);
}
// Function to get the program name from the user
function getProgramName() {
return __awaiter(this, void 0, void 0, function () {
var fileName, path;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, vscode.window.showInputBox({
placeHolder: "Please enter the name of a futil file in the workspace folder",
value: "default.futil",
})];
case 1:
fileName = _a.sent();
if (fileName) {
if (!fileName.startsWith("/")) {
path = require("path");
return [2 /*return*/, path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, fileName)];
}
return [2 /*return*/, fileName];
}
else {
return [2 /*return*/, null];
}
return [2 /*return*/];
}
});
});
}
// async function getProgramName() {
// const fileName = await vscode.window.showInputBox({
// placeHolder:
// "Please enter the name of a futil file in the workspace folder",
// value: "default.futil",
// });
// if (fileName) {
// if (!fileName.startsWith("/")) {
// const path = require("path");
// return path.join(
// vscode.workspace.workspaceFolders[0].uri.fsPath,
// fileName
// );
// }
// return fileName;
// } else {
// return null;
// }
// }
// Factory for multi-session
var CiderDebugAdapterDescriptorFactoryServer = /** @class */ (function () {
function CiderDebugAdapterDescriptorFactoryServer(adapterPath, stdPath, workspace, outputChannel) {
Expand All @@ -86,53 +43,62 @@ var CiderDebugAdapterDescriptorFactoryServer = /** @class */ (function () {
}
CiderDebugAdapterDescriptorFactoryServer.prototype.createDebugAdapterDescriptor = function (session) {
// Return a new debug adapter descriptor
logToPanel("creating adapter descriptor");
return new vscode.DebugAdapterServer(this._startDebugServer(session));
};
CiderDebugAdapterDescriptorFactoryServer.prototype._startDebugServer = function (session) {
logToPanel("start of startDebugServer");
logToPanel("line 57: create_DA_Desc");
// default port: 8888
var port = vscode.workspace.getConfiguration("cider-dap").port;
// adjust this logic to use promises too
if (!this.adapter.isServerRunning()) {
logToPanel("server is not running");
this.adapter.start(port);
logToPanel("started dap-server");
var adapterPromise = this.adapter.start(port);
return adapterPromise.then(function (res) {
logToPanel("line 66: connect to debugger");
return new vscode.DebugAdapterServer(res);
}, function () { throw "Failed to start debug server"; });
}
else {
logToPanel("line 71: connect to debugger");
return new vscode.DebugAdapterServer(port);
}
logToPanel("exiting startDebugging");
return port;
};
return CiderDebugAdapterDescriptorFactoryServer;
}());
var CiderDebugAdapter = /** @class */ (function () {
function CiderDebugAdapter(adapterPath, stdPath, cwd, outputChannel) {
logToPanel("inside CiderDebugAdapter");
logToPanel("line 83: CDA constructor start");
this.adapterPath = adapterPath;
this.stdPath = stdPath;
this.cwd = cwd;
this.outputChannel = outputChannel;
this.adapterProcess = null;
logToPanel("at the end of ciderDebugAdapter");
logToPanel("line 89: CDA constructor end");
}
CiderDebugAdapter.prototype.isServerRunning = function () {
logToPanel("checking if server is running");
logToPanel("line 92: checking if server is running");
return this.adapterProcess != null && this.adapterProcess.exitCode == null;
};
// Start the debug adapter process
CiderDebugAdapter.prototype.start = function (port) {
logToPanel("beginning of start");
var _this = this;
logToPanel("line 97: CDA start(port)");
// Spawn a new child process for the debug adapter
// Include the port as a command line argument
this.adapterProcess = cp.spawn(this.adapterPath, ["--port", port, "--tcp", "-l", this.stdPath], { cwd: this.cwd });
// Attach event listener to capture standard output of the adapter process and log it to the output channel
this.adapterProcess.stdout.on("data", function (data) {
logToPanel(data.toString());
});
// Attach event listener to capture standard error of the adapter process and log it to the output channel
this.adapterProcess.stderr.on("data", function (data) {
logToPanel(data.toString());
});
this.adapterProcess.on("spawn", function () {
logToPanel("Debugger started on port " + port + "!");
return new Promise(function (resolve, reject) {
_this.adapterProcess = cp.spawn(_this.adapterPath, ["--port", port, "--tcp", "-l", _this.stdPath], { cwd: _this.cwd });
// Attach event listener to capture standard output of the adapter process and log it to the output channel
_this.adapterProcess.stdout.on("data", function (data) {
logToPanel(data.toString());
});
// Attach event listener to capture standard error of the adapter process and log it to the output channel
_this.adapterProcess.stderr.on("data", function (data) {
logToPanel(data.toString());
});
_this.adapterProcess.on("spawn", function () {
logToPanel("Debugger started on port " + port + "!");
setTimeout(function () { return resolve(port); }, 200);
});
_this.adapterProcess.on("error", function () {
logToPanel("Debugger failed to start");
reject(-1);
});
});
};
CiderDebugAdapter.prototype.stop = function () {
Expand Down Expand Up @@ -189,6 +155,7 @@ function stopDebugging() {
}
}
function deactivate() {
//kill server
logToPanel("deactivate");
}
module.exports = {
Expand Down
125 changes: 66 additions & 59 deletions cider-dap/calyxDebug/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import cp = require("child_process");
import net = require("net");
import * as vscode from 'vscode';
import * as cp from "child_process"
import * as Net from "net"

// Hold the debug adapter instance
let debugAdapter = null;
Expand All @@ -9,31 +9,31 @@ let programName = null; // Store the program name
let outputChannel = vscode.window.createOutputChannel("Cider dap");

function logToPanel(message) {
console.log("inside logPanel");
//console.log("inside logPanel");
outputChannel.appendLine(message);
}

// Function to get the program name from the user
async function getProgramName() {
const fileName = await vscode.window.showInputBox({
placeHolder:
"Please enter the name of a futil file in the workspace folder",
value: "default.futil",
});

if (fileName) {
if (!fileName.startsWith("/")) {
const path = require("path");
return path.join(
vscode.workspace.workspaceFolders[0].uri.fsPath,
fileName
);
}
return fileName;
} else {
return null;
}
}
// async function getProgramName() {
// const fileName = await vscode.window.showInputBox({
// placeHolder:
// "Please enter the name of a futil file in the workspace folder",
// value: "default.futil",
// });

// if (fileName) {
// if (!fileName.startsWith("/")) {
// const path = require("path");
// return path.join(
// vscode.workspace.workspaceFolders[0].uri.fsPath,
// fileName
// );
// }
// return fileName;
// } else {
// return null;
// }
// }

// Factory for multi-session
class CiderDebugAdapterDescriptorFactoryServer {
Expand All @@ -54,25 +54,26 @@ class CiderDebugAdapterDescriptorFactoryServer {

createDebugAdapterDescriptor(session) {
// Return a new debug adapter descriptor
logToPanel("creating adapter descriptor");

return new vscode.DebugAdapterServer(this._startDebugServer(session));
}

_startDebugServer(session) {
logToPanel("start of startDebugServer");
logToPanel("line 57: create_DA_Desc");
// default port: 8888
const port = vscode.workspace.getConfiguration("cider-dap").port;
// adjust this logic to use promises too

if (!this.adapter.isServerRunning()) {
logToPanel("server is not running");
this.adapter.start(port);
logToPanel("started dap-server");
let adapterPromise = this.adapter.start(port)
return adapterPromise.then((res) => {
logToPanel("line 66: connect to debugger")
return new vscode.DebugAdapterServer(res);
}, () => { throw "Failed to start debug server" })
}
else {
logToPanel("line 71: connect to debugger")
return new vscode.DebugAdapterServer(port)
}

logToPanel("exiting startDebugging");
return port;
}
}

class CiderDebugAdapter {
adapterPath: string;
stdPath: string;
Expand All @@ -82,43 +83,48 @@ class CiderDebugAdapter {
isRunning: boolean;

constructor(adapterPath, stdPath, cwd, outputChannel) {
logToPanel("inside CiderDebugAdapter");
logToPanel("line 83: CDA constructor start");
this.adapterPath = adapterPath;
this.stdPath = stdPath;
this.cwd = cwd;
this.outputChannel = outputChannel;
this.adapterProcess = null;
logToPanel("at the end of ciderDebugAdapter");
logToPanel("line 89: CDA constructor end");
}
isServerRunning() {
logToPanel("checking if server is running");
logToPanel("line 92: checking if server is running");
return this.adapterProcess != null && this.adapterProcess.exitCode == null;
}
// Start the debug adapter process
start(port) {
logToPanel("beginning of start");
logToPanel("line 97: CDA start(port)");

// Spawn a new child process for the debug adapter
// Include the port as a command line argument
this.adapterProcess = cp.spawn(
this.adapterPath,
["--port", port, "--tcp", "-l", this.stdPath],
{ cwd: this.cwd }
);

// Attach event listener to capture standard output of the adapter process and log it to the output channel
this.adapterProcess.stdout.on("data", (data) => {
logToPanel(data.toString());
});

// Attach event listener to capture standard error of the adapter process and log it to the output channel
this.adapterProcess.stderr.on("data", (data) => {
logToPanel(data.toString());
});

this.adapterProcess.on("spawn", () => {
logToPanel("Debugger started on port " + port + "!");
});
return new Promise<number>((resolve, reject) => {
this.adapterProcess = cp.spawn(
this.adapterPath,
["--port", port, "--tcp", "-l", this.stdPath],
{ cwd: this.cwd }
);
// Attach event listener to capture standard output of the adapter process and log it to the output channel
this.adapterProcess.stdout.on("data", (data) => {
logToPanel(data.toString());
});

// Attach event listener to capture standard error of the adapter process and log it to the output channel
this.adapterProcess.stderr.on("data", (data) => {
logToPanel(data.toString());
});
this.adapterProcess.on("spawn", () => {
logToPanel("Debugger started on port " + port + "!");
setTimeout(() => resolve(port), 200)
});
this.adapterProcess.on("error", () => {
logToPanel("Debugger failed to start");
reject(-1)
});
})
}

stop() {
Expand Down Expand Up @@ -192,6 +198,7 @@ function stopDebugging() {
}

function deactivate() {
//kill server
logToPanel("deactivate");
}

Expand Down

0 comments on commit 50e7572

Please sign in to comment.