diff --git a/extension.js b/extension.js index deb44f5..7fd5f23 100644 --- a/extension.js +++ b/extension.js @@ -56,6 +56,44 @@ async function runPythonCommand(scriptName) { */ } +async function generateDebugConfig() { + const workspaceFolders = vscode.workspace.workspaceFolders; + if (!workspaceFolders) { + vscode.window.showErrorMessage("No workspace opened. Please open a folder to generate the debug configuration."); + return; + } + + const launchConfig = vscode.workspace.getConfiguration('launch', workspaceFolders[0].uri); + const existingConfigs = launchConfig.get('configurations') || []; + + const metaflowConfigName = "Metaflow Debug"; + const hasConfig = existingConfigs.some(config => config.name === metaflowConfigName); + + if (hasConfig) { + vscode.window.showInformationMessage("Metaflow Debug configuration already exists in launch.json."); + return; + } + + const newConfig = { + name: metaflowConfigName, + type: "python", + request: "launch", + program: "${file}", + args: [ + "run", + "--max-workers", + "1" + ], + subProcess: true, + console: "integratedTerminal" + }; + + existingConfigs.push(newConfig); + + await launchConfig.update('configurations', existingConfigs, vscode.ConfigurationTarget.WorkspaceFolder); + vscode.window.showInformationMessage("Metaflow Debug configuration has been added to launch.json."); +} + function activate(context) { const runCmd = vscode.commands.registerCommand( 'extension.runPythonFunction', @@ -67,7 +105,32 @@ function activate(context) { () => runPythonCommand('spin_func') ); - context.subscriptions.push(runCmd, spinCmd); + const genConfigCmd = vscode.commands.registerCommand( + 'extension.generateDebugConfig', + () => generateDebugConfig() + ); + + const provider = vscode.debug.registerDebugConfigurationProvider('python', { + provideDebugConfigurations(folder, token) { + return [ + { + name: "Metaflow Debug", + type: "python", + request: "launch", + program: "${file}", + args: [ + "run", + "--max-workers", + "1" + ], + subProcess: true, + console: "integratedTerminal" + } + ]; + } + }); + + context.subscriptions.push(runCmd, spinCmd, genConfigCmd, provider); } function deactivate() { diff --git a/package.json b/package.json index 31a7c2f..9c3d9c0 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,14 @@ "displayName": "Run and Spin Metaflow", "version": "0.0.7", "publisher": "local", - "engines": { "vscode": "^1.80.0" }, + "engines": { + "vscode": "^1.80.0" + }, "activationEvents": [ "onCommand:extension.runPythonFunction", - "onCommand:extension.spinPythonFunction" + "onCommand:extension.spinPythonFunction", + "onCommand:extension.generateDebugConfig", + "onDebugInitialConfigurations" ], "repository": { "type": "git", @@ -22,6 +26,10 @@ { "command": "extension.spinPythonFunction", "title": "Spin the current step" + }, + { + "command": "extension.generateDebugConfig", + "title": "Metaflow: Generate Debug Config" } ], "keybindings": [ @@ -37,4 +45,4 @@ } ] } -} +} \ No newline at end of file