Skip to content

Commit

Permalink
Merge pull request #10 from mlops-club/feature/data-viewing
Browse files Browse the repository at this point in the history
Create the equivalent of `code --add ~/bentoml` command in the extension.
  • Loading branch information
shilongjaycui authored Mar 29, 2024
2 parents f74db7a + 2a06a19 commit 427489b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bentoml-playground-workspace/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"bentoml.bentomlHomeDir": "~/bentoml"
"bentoml.bentomlHomeDir": "bentoml"
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bentoml",
"publisher": "mlops-club",
"version": "0.0.4",
"version": "0.0.5",
"displayName": "BentoML",
"icon": "src/resources/bentoml-logo.png",
"author": {
Expand Down Expand Up @@ -60,8 +60,8 @@
"properties": {
"bentoml.bentomlHomeDir": {
"type": "string",
"description": "Path to BentoML home directory. Defaults to `~/bentoml`",
"default": "~/bentoml"
"description": "Path to BentoML home directory. Defaults to `bentoml`",
"default": "bentoml"
}
}
},
Expand Down Expand Up @@ -99,6 +99,10 @@
"command": "bentoml.serveBentoInTerminal",
"title": "BentoML: Serve Bento in new Terminal"
},
{
"command": "bentoml.openBentomlHomeDir",
"title": "BentoML: Open BentoML Home Directory in VS Code Workspace"
},
{
"command": "bentoml.refreshModelEntry",
"title": "BentoML: Refresh models",
Expand Down
39 changes: 37 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import * as consts from './common/constants';
import * as os from 'os';
import * as path from 'path';
import {
BentoMlExtensionSettings as BentoMlExtensionSettings,
Expand Down Expand Up @@ -190,13 +191,47 @@ export async function activate(context: vscode.ExtensionContext) {
}
});

let disposable = vscode.commands.registerCommand(`${consts.EXTENSION_ID}.installPythonDependencies`, async () => {
let dependencyInstallationDisposable = vscode.commands.registerCommand(`${consts.EXTENSION_ID}.installPythonDependencies`, async () => {
// The code you place here will be executed every time your command is executed
await ensureBentoMlCliIsAvailable();
vscode.window.showInformationMessage(`[${consts.EXTENSION_NAME}] Python dependencies installed successfully!`);
});
context.subscriptions.push(dependencyInstallationDisposable);

context.subscriptions.push(disposable);
let homeDirOpeningDisposable = vscode.commands.registerCommand(`${consts.EXTENSION_ID}.openBentomlHomeDir`, async () => {
const extensionConfig = vscode.workspace.getConfiguration();

const homeDir = os.homedir();
const bentomlDirPath = extensionConfig.get<string>('bentoml.bentomlHomeDir') || "bentoml";
const bentomlDir = path.resolve(homeDir, bentomlDirPath);
console.log(`bentomlDir: ${bentomlDir}`);

try {
const bentomlDirUri = vscode.Uri.file(bentomlDir);
const bentomlWorkspaceFolder: vscode.WorkspaceFolder = {
uri: bentomlDirUri,
name: 'bentoml-home-directory', // Optional
index: 0
};

const currentFolders = vscode.workspace.workspaceFolders ?? [];
const allFolders: vscode.WorkspaceFolder[] = [...currentFolders, bentomlWorkspaceFolder];
for (const folder of allFolders) {
console.log(`folder URI (before): ${folder.uri}`);
}
const added: boolean = vscode.workspace.updateWorkspaceFolders(0, 1, ...allFolders);
console.log(`Added? ${added}`);
const newCurrentFolders = vscode.workspace.workspaceFolders ?? [];
for (const folder of newCurrentFolders) {
console.log(`folder URI (after): ${folder.uri}`);
}
} catch (error) {
console.error('Error opening BentoML home directory:', error);
vscode.window.showErrorMessage('Error opening BentoML home directory');
}

});
context.subscriptions.push(homeDirOpeningDisposable);

// notify the user that the extension activated successfully
vscode.window.showInformationMessage(`[${consts.EXTENSION_NAME}] extension loaded!`);
Expand Down

0 comments on commit 427489b

Please sign in to comment.