Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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() {
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -22,6 +26,10 @@
{
"command": "extension.spinPythonFunction",
"title": "Spin the current step"
},
{
"command": "extension.generateDebugConfig",
"title": "Metaflow: Generate Debug Config"
}
],
"keybindings": [
Expand All @@ -37,4 +45,4 @@
}
]
}
}
}