Skip to content

Commit

Permalink
can print as well as invoke the adpater, need to figure outpassing fi…
Browse files Browse the repository at this point in the history
…le as an argument
  • Loading branch information
Basant-khalil committed Jul 26, 2023
1 parent dddb775 commit 2ae9930
Showing 1 changed file with 88 additions and 43 deletions.
131 changes: 88 additions & 43 deletions cider-dap/calyxDebug/extension.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,109 @@
const vscode = require('vscode');
const cp = require('child_process');

let outputChannel;
// Create an output channel
let outputChannel = vscode.window.createOutputChannel("cider dap");

function startDebugging() {
// After attaching and starting debugging, call the panel printing function
logToPanel('Debugger attached and debugging started.');
logToPanel('Some additional information...');
}

function logToPanel(message) {
// Create an output channel
if (!outputChannel) {
outputChannel = vscode.window.createOutputChannel('Cider DAP');
// CiderDebugAdapter class for managing debug adapter process
class CiderDebugAdapter {
constructor(adapterPath, cwd, outputChannel) {
this.adapterPath = adapterPath;
this.cwd = cwd;
this.outputChannel = outputChannel;
this.adapterProcess = null;
}

// Log the message to the output channel
outputChannel.appendLine(message);
// Start the debug adapter process
start() {
logToPanel('Debugger starting...');

// Show the message in the panel as well
vscode.window.showInformationMessage(message);
}
// Spawn a new child process for the debug adapter
this.adapterProcess = cp.spawn(this.adapterPath, {
cwd: this.cwd
});

function activate(context) {
// Create the outputChannel only once when the extension activates
outputChannel = vscode.window.createOutputChannel('Cider DAP');
// 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());
});

// Register a command to start debugging
const disposableStartDebugging = vscode.commands.registerCommand('extension.cider-dap.startDebugging', startDebugging);
context.subscriptions.push(disposableStartDebugging);
// 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());
});
logToPanel('Debugger started!');
}

// Register a command for testing purposes
const disposableTest = vscode.commands.registerCommand('extension.cider-dap.test', function () {
// The code you want to run when the command is executed
// Stop the debug adapter process
stop() {
if (this.adapterProcess) {
// Terminate the adapter process and set it to null
this.adapterProcess.kill();
this.adapterProcess = null;
logToPanel('Debugger stopped.');
} else {
logToPanel('No running debug adapter to stop.');
}
}
}

// Log to the output channel
logToPanel('Executing extension.cider-dap.test');
// Start debugging
function startDebugging() {
if (!debugAdapter) {
// Set the path to the debug adapter and current working directory
const adapterPath = '/home/basantkhalil/calyx2/target/debug/cider-dap';
const cwd = vscode.workspace.rootPath;

// Listen for stdout data
const proc = cp.spawn('your_command_here', ['arg1', 'arg2']); // Replace 'your_command_here' with the actual command to be executed
proc.stdout.on('data', (data) => {
logToPanel(`stdout: ${data}`);
});
// Create a new instance of the CiderDebugAdapter
debugAdapter = new CiderDebugAdapter(adapterPath, cwd, outputChannel);
}

// Listen for stderr data
proc.stderr.on('data', (data) => {
logToPanel(`stderr: ${data}`);
});
// Start the debug adapter
debugAdapter.start();
}

// Listen for close event
proc.on('close', (code) => {
logToPanel(`child process exited with code ${code}`);
});
});
// Stop debugging
function stopDebugging() {
if (debugAdapter) {
// Stop the running debug adapter process
debugAdapter.stop();
} else {
logToPanel('No running debug adapter to stop.');
}
}

context.subscriptions.push(disposableTest);
// Variable to hold the debug adapter instance
let debugAdapter = null;

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

function deactivate() { }
// Activate the extension
function activate(context) {
logToPanel('Hello, your extension is now activated!');

// Register the 'extension.startDebugging' command
let disposableStart = vscode.commands.registerCommand('cider.startDebugging', startDebugging);
console.log("after startDebugging");
context.subscriptions.push(disposableStart);

// Register the 'extension.stopDebugging' command
let disposableStop = vscode.commands.registerCommand('cider.stopDebugging', stopDebugging);
context.subscriptions.push(disposableStop);

// Register the debug adapter descriptor factory
vscode.debug.registerDebugAdapterDescriptorFactory('cider-dap', {
createDebugAdapterDescriptor: (_session) => {
return new vscode.DebugAdapterExecutable('./cider-dap');
}
});
}
function deactivate() {
logToPanel("deactivate");
}
// Export the activate function to be used as the entry point for the extension
module.exports = {
activate,
deactivate
Expand Down

0 comments on commit 2ae9930

Please sign in to comment.