From 94d9148d876ba57c68467ed2c68a3085c5d958b6 Mon Sep 17 00:00:00 2001 From: Basant-khalil Date: Wed, 2 Aug 2023 11:15:49 -0400 Subject: [PATCH] try it with multi-session --- .vscode/launch.json | 12 +++-- cider-dap/calyxDebug/extension.js | 89 ++++++++++++++++--------------- cider-dap/src/main.rs | 9 +++- 3 files changed, 61 insertions(+), 49 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3a86a10fe2..d71e83dd1f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,11 +4,13 @@ { "type": "cider-dap", "request": "launch", - "name": "Launch Program (Single Session)", - "args": [ - "${file}" - ], - "program": "${command:cider.startDebugging}", + "name": "Launch Program (Multi Session)", + "debugServer": 8888, + "program": "${file}", + "preLaunchTask": { + "type": "shell", + "command": "${command:cider.startDebugging}" + }, "stopOnEntry": true, }, { diff --git a/cider-dap/calyxDebug/extension.js b/cider-dap/calyxDebug/extension.js index b69f9158d0..2115ebafaf 100644 --- a/cider-dap/calyxDebug/extension.js +++ b/cider-dap/calyxDebug/extension.js @@ -2,10 +2,11 @@ const vscode = require('vscode'); const cp = require('child_process'); const { config } = require('process'); + // Create output channel let outputChannel = vscode.window.createOutputChannel("cider dap"); -// Class for debug adapter process + class CiderDebugAdapter { constructor(adapterPath, cwd, outputChannel) { this.adapterPath = adapterPath; @@ -13,10 +14,11 @@ class CiderDebugAdapter { this.outputChannel = outputChannel; this.adapterProcess = null; } + + // Start the debug adapter process - async start() { + async start(port) { // accept the port parameter logToPanel('Debugger starting...'); - // Get the program name from the user const programName = await getProgramName(); @@ -24,7 +26,6 @@ class CiderDebugAdapter { logToPanel('No program selected. Aborting debugging.'); return; } - // Verify if the file exists at the provided path const fs = require('fs'); if (!fs.existsSync(programName)) { @@ -33,7 +34,8 @@ class CiderDebugAdapter { } // Spawn a new child process for the debug adapter - this.adapterProcess = cp.spawn(this.adapterPath, [programName], { cwd: this.cwd }); + // Include the port as a command line argument + this.adapterProcess = cp.spawn(this.adapterPath, [programName, '--port', port, "--tcp"], { 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) => { @@ -45,16 +47,16 @@ class CiderDebugAdapter { logToPanel(data.toString()); }); - logToPanel('Debugger started!'); + logToPanel('Debugger started on port ' + port + '!'); } // Stop debug adapter process stop() { if (this.adapterProcess) { - // Terminate the adapter process and set it to null this.adapterProcess.kill(); this.adapterProcess = null; + this.isRunning = false; logToPanel('Debugger stopped.'); } else { logToPanel('No running debug adapter to stop.'); @@ -62,43 +64,18 @@ class CiderDebugAdapter { } } -// Start debugging -async function startDebugging(arg1) { - logToPanel("inside startDebugging"); - console.log(arg1); - 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; - - // Create an instance of the CiderDebugAdapter - debugAdapter = new CiderDebugAdapter(adapterPath, cwd, outputChannel); - - // Start the debug adapter with the selected program - debugAdapter.start(); - debugAdapter = null; //will need to change with multi session - } -} - -// Stop debugging -function stopDebugging() { - if (debugAdapter) { - // Stop the running debug adapter - debugAdapter.stop(); - } else { - logToPanel('No running debug adapter to stop.'); - } -} // Hold the debug adapter instance let debugAdapter = null; let programName = null; // Store the program name + function logToPanel(message) { 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({ @@ -107,20 +84,47 @@ async function getProgramName() { }); if (fileName) { - // If the fileName is a relative path (not starting with "/"), - // prepend the path to the workspace folder if (!fileName.startsWith('/')) { - // Also, use path.join to properly join paths const path = require('path'); return path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, fileName); } - // If the fileName is an absolute path, return it as is return fileName; } else { - // Return null if the user canceled the input return null; } } +// Start debugging +async function startDebugging(arg) { + logToPanel("inside startDebugging"); + + if (!debugAdapter) { + const adapterPath = '/home/basantkhalil/calyx2/target/debug/cider-dap'; + const cwd = vscode.workspace.rootPath; + + debugAdapter = new CiderDebugAdapter(adapterPath, cwd, outputChannel); + } + // Prompt for the port + const portInput = await vscode.window.showInputBox({ + placeHolder: 'Please enter the port number', + value: '8888' // This is the default value + }); + + // If the user entered a value, parse it to an integer + const port = portInput ? parseInt(portInput, 10) : 1234; + await debugAdapter.start(port); + logToPanel("exiting startDebugging"); + return; +} + + +// Stop debugging +function stopDebugging() { + if (debugAdapter) { + debugAdapter.stop(); + } else { + logToPanel('No running debug adapter to stop.'); + } +} // Activate the extension @@ -132,9 +136,6 @@ function activate(context) { let disposableStop = vscode.commands.registerCommand('cider.stopDebugging', stopDebugging); context.subscriptions.push(disposableStop); - /* - // Dispose the provider when the extension is deactivated - context.subscriptions.push(provider); */ logToPanel('Hello, your extension is now activated!'); } @@ -144,7 +145,11 @@ function deactivate() { logToPanel("deactivate"); } + module.exports = { activate, deactivate }; + + + diff --git a/cider-dap/src/main.rs b/cider-dap/src/main.rs index f5ba5e999f..28c8a7c1d4 100644 --- a/cider-dap/src/main.rs +++ b/cider-dap/src/main.rs @@ -35,20 +35,24 @@ fn main() -> Result<(), MyAdapterError> { let adapter = MyAdapter::new(file); if opts.is_multi_session { + eprintln!("running multi-session"); let listener = TcpListener::bind(("127.0.0.1", opts.port))?; + eprintln!("bound on port: {} ", opts.port); let (stream, addr) = listener.accept()?; println!("Accepted client on: {}", addr); let read_stream = BufReader::new(stream.try_clone()?); let write_stream = BufWriter::new(stream); let server = Server::new(read_stream, write_stream); + run_server(server, adapter)?; } else { + eprintln!("running single-session"); let write = BufWriter::new(stdout()); let read = BufReader::new(stdin()); let server = Server::new(read, write); run_server(server, adapter)?; } - + eprintln!("exited run_Server"); Ok(()) } @@ -56,5 +60,6 @@ fn run_server( _server: Server, _adapter: MyAdapter, ) -> AdapterResult<()> { - todo!() + println!("inside run_server"); + Ok(()) //still need to implement this }