Skip to content

Commit

Permalink
Add status bar that displays the currently active stack
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan37 committed Mar 7, 2024
1 parent 7e064a8 commit 7ef69d2
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 108 deletions.
File renamed without changes.
8 changes: 0 additions & 8 deletions zenml-studio/.gitignore → .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ Thumbs.db
.sass-cache
.eslintcache
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results

.vscode-test/

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions zenml-studio/package.json → package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
"categories": [
"Other"
],
"activationEvents": [],
"activationEvents": [
"onStartupFinished"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "zenml-studio.helloWorld",
"title": "Hello World"
"command": "zenml.showActiveStack",
"title": "Show Active ZenML Stack"
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions src/commands/stackCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { execCLICommand } from '../utils/shell';

/**
* Fetches the current active stack using the ZenML CLI.
*/
export function getActiveStack(): Promise<string> {
return execCLICommand('zenml stack get');
}
16 changes: 16 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as vscode from 'vscode';
import { ZenMLStatusBar } from './views/statusBar';

export function activate(context: vscode.ExtensionContext) {
console.log('ZenML Studio is now active!');

const zenMLStatusBar = ZenMLStatusBar.getInstance();

const refreshCommand = vscode.commands.registerCommand('zenml.showActiveStack', () => {
zenMLStatusBar.updateStatusBar();
});

context.subscriptions.push(refreshCommand);
}

export function deactivate() { }
File renamed without changes.
17 changes: 17 additions & 0 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { exec } from 'child_process';

/**
* Executes a CLI command and returns a promise that resolves with the command's stdout.
*/
export function execCLICommand(command: string): Promise<string> {
return new Promise((resolve, reject) => {

exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve(stdout.trim());
});
});
}
56 changes: 56 additions & 0 deletions src/views/statusBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as vscode from 'vscode';
import { getActiveStack } from '../commands/stackCommands';

export class ZenMLStatusBar {
private static instance: ZenMLStatusBar;
private statusBar: vscode.StatusBarItem;
private constructor() {
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
this.statusBar.command = 'zenml.showActiveStack';
this.updateStatusBar();
}

public static getInstance(): ZenMLStatusBar {
if (!ZenMLStatusBar.instance) {
ZenMLStatusBar.instance = new ZenMLStatusBar();
// ZenMLStatusBar.instance.startAutoRefresh();
}
return ZenMLStatusBar.instance;
}

// public startAutoRefresh() {
// const interval = 30000;
// setInterval(() => {
// this.updateStatusBar();
// }, interval);
// }

public show() {
this.statusBar.show();
}

public hide() {
this.statusBar.hide();
}

public updateStatusBar() {
console.log('Updating ZenML active stack...');

getActiveStack().then((fullActiveStackText) => {
/**
* The cli command `zenml stack get` outputs the line below:
* The global active stack is: 'default'
* 'default' is the actual string we want to display in the status bar.
*/
const match = fullActiveStackText.match(/'([^']+)'/); // matches text within single quotes
const activeStack = match ? match[1] : 'Error parsing stack name';
this.statusBar.text = `Active Stack: ${activeStack}`;
this.statusBar.tooltip = 'Click to refresh the active ZenML stack';
this.show();
}).catch((error) => {
console.error('Failed to fetch active ZenML stack:', error);
this.statusBar.text = `Active Stack: Error`;
this.show();
});
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
71 changes: 0 additions & 71 deletions zenml-studio/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions zenml-studio/src/extension.ts

This file was deleted.

0 comments on commit 7ef69d2

Please sign in to comment.