-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status bar that displays the currently active stack
- Loading branch information
Showing
16 changed files
with
102 additions
and
108 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.