update mocha-vscode to better work with different SUV backends introduced in mocha-suv@9407922
This commit is contained in:
parent
d38212fbb3
commit
431fa59a71
42
package.json
42
package.json
@ -13,6 +13,11 @@
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "mocha.suvmanager.set_selected_item",
|
||||
"title": "",
|
||||
"category": "Mocha"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_manager",
|
||||
"title": "Manage SUVs",
|
||||
@ -24,9 +29,19 @@
|
||||
"shortTitle": "Show in Web",
|
||||
"category": "Mocha"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_copy_id",
|
||||
"title": "Copy SUV ID",
|
||||
"category": "Mocha"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_up",
|
||||
"title": "Launch SUV",
|
||||
"title": "Start SUV",
|
||||
"category": "Mocha"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_down",
|
||||
"title": "Stop SUV",
|
||||
"category": "Mocha"
|
||||
},
|
||||
{
|
||||
@ -38,6 +53,12 @@
|
||||
"dark": "icons/commands/add-connection-dark.svg"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_refresh",
|
||||
"title": "Refresh SUV List",
|
||||
"category": "Mocha",
|
||||
"icon": "$(refresh)"
|
||||
},
|
||||
{
|
||||
"command": "mocha.add_documentation_comment",
|
||||
"title": "Add Documentation Comment",
|
||||
@ -150,17 +171,32 @@
|
||||
"command": "mocha.suvmanager.suv_new",
|
||||
"when": "view == mocha.suvManager",
|
||||
"group": "navigation@1"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_refresh",
|
||||
"when": "view == mocha.suvManager",
|
||||
"group": "navigation@1"
|
||||
}
|
||||
],
|
||||
"view/item/context": [
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_show",
|
||||
"group": "YourGroup@1",
|
||||
"group": "0_view@1",
|
||||
"when": "view == mocha.suvManager"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_up",
|
||||
"group": "YourGroup@2",
|
||||
"group": "1_control@1",
|
||||
"when": "view == mocha.suvManager"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_down",
|
||||
"group": "1_control@1",
|
||||
"when": "view == mocha.suvManager"
|
||||
},
|
||||
{
|
||||
"command": "mocha.suvmanager.suv_copy_id",
|
||||
"group": "2_copy",
|
||||
"when": "view == mocha.suvManager"
|
||||
}
|
||||
]
|
||||
|
||||
@ -2,13 +2,15 @@
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { SuvManagerTreeDataProvider } from './SuvManagerTreeDataProvider';
|
||||
import { GenericTreeDataProvider } from './tdp/GenericTreeDataProvider';
|
||||
import { GenericTreeDataItem } from './tdp/GenericTreeDataItem';
|
||||
import { ModuleExplorerTreeDataProvider } from './ModuleExplorerTreeDataProvider';
|
||||
import { userInfo } from 'os';
|
||||
import { Machine } from './Machine';
|
||||
|
||||
import { SuvManagerTreeDecorationProvider } from './suvManager/SuvManagerTreeDecorationProvider';
|
||||
import { SuvManagerTreeDataProvider } from './suvManager/SuvManagerTreeDataProvider';
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
import https from 'node:https';
|
||||
@ -16,7 +18,10 @@ import https from 'node:https';
|
||||
const cp = require('child_process');
|
||||
|
||||
let dpModuleExplorer = new ModuleExplorerTreeDataProvider();
|
||||
let treeSuvManager : vscode.TreeView<Machine> | undefined = undefined;
|
||||
let treeSuvManager: vscode.TreeView<Machine> | undefined = undefined;
|
||||
|
||||
// register the decoration provider
|
||||
vscode.window.registerFileDecorationProvider(new SuvManagerTreeDecorationProvider());
|
||||
|
||||
export function mkotsuri(suvId : string, tenantName : string, command : string, serviceName : string = "zq", version : string = "v1") : vscode.Uri
|
||||
{
|
||||
@ -129,6 +134,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
treeSuvManager = vscode.window.createTreeView("mocha.suvManager", { "canSelectMany": true, "showCollapseAll": true, "treeDataProvider": treeDataProvider });
|
||||
treeDataProvider.treeview = treeSuvManager;
|
||||
treeSuvManager.badge = { "value": 1, "tooltip": "1 SUV(s) running" };
|
||||
|
||||
|
||||
|
||||
let treeModuleExplorer = vscode.window.createTreeView("mocha.moduleExplorer", { "canSelectMany": true, "showCollapseAll": true, "treeDataProvider": dpModuleExplorer });
|
||||
@ -141,8 +147,16 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// This line of code will only be executed once when your extension is activated
|
||||
console.log('Congratulations, your extension "suvmanager" is now active!');
|
||||
|
||||
vscode.commands.registerCommand("mocha.suvmanager.set_selected_item", (item:vscode.TreeItem) => {
|
||||
cp.exec('mocha suv status -f csv ' + item.label, (err: string, stdout: string, stderr: string) => {
|
||||
let listSuvs = new Array<Machine>();
|
||||
let list = stdout.trim().split('\n');
|
||||
console.log(list[0]);
|
||||
});
|
||||
});
|
||||
|
||||
let cmd_zq_import_function_signature = vscode.commands.registerCommand("mocha.zq_import_function_signature", () => {
|
||||
/*
|
||||
/*s
|
||||
const rootCas = require('ssl-root-cas').create();
|
||||
rootCas.addFile(path.resolve(__dirname, 'localhost.crt'));
|
||||
https.globalAgent.options.ca = rootCas;
|
||||
@ -234,18 +248,26 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
vscode.window.showInformationMessage('Add code here to display SUV Manager panel!');
|
||||
});
|
||||
context.subscriptions.push(cmd_suv_manager);
|
||||
|
||||
let cmd_suv_refresh = vscode.commands.registerCommand('mocha.suvmanager.suv_refresh', () => {
|
||||
vscode.window.showInformationMessage('Add code here to display SUV Manager panel!');
|
||||
});
|
||||
context.subscriptions.push(cmd_suv_refresh);
|
||||
|
||||
let cmd_suv_show = vscode.commands.registerCommand('mocha.suvmanager.suv_show', (...args) => {
|
||||
if (args.length === 0) {
|
||||
cp.exec('mocha suv list', (err: string, stdout: string, stderr: string) => {
|
||||
cp.exec('mocha suv status -f csv', (err: string, stdout: string, stderr: string) => {
|
||||
vscode.window.showInformationMessage(stdout);
|
||||
let list = stdout.split(' ');
|
||||
let list = stdout.split('\n');
|
||||
let list2 = new Array<string>();
|
||||
list.forEach((element) => {
|
||||
list2.push(element.trim());
|
||||
let list3 = element.trim().split(',');
|
||||
if (list3[2] === 'running') {
|
||||
list2.push(list3[0].trim());
|
||||
}
|
||||
});
|
||||
|
||||
var w = vscode.window.showQuickPick(list2, { "title": "Open SUV in Web Browser", "placeHolder": "Choose an SUV to open" }).then((value) => {
|
||||
var w = vscode.window.showQuickPick(list2, { "title": "Launch SUV", "placeHolder": "Pick an SUV to launch (e.g. i-012345678)" }).then((value) => {
|
||||
if (value !== undefined) {
|
||||
openWebBrowser(vscode.Uri.parse("https://" + value + ".privatesuv.com"));
|
||||
}
|
||||
@ -262,14 +284,16 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
let cmd_suv_up = vscode.commands.registerCommand('mocha.suvmanager.suv_up', (...args) => {
|
||||
if (args.length === 0) {
|
||||
cp.exec('mocha suv list', (err: string, stdout: string, stderr: string) => {
|
||||
|
||||
|
||||
vscode.window.showInformationMessage(stdout);
|
||||
let list = stdout.split(' ');
|
||||
let list = stdout.split('\n');
|
||||
let list2 = new Array<string>();
|
||||
list.forEach((element) => {
|
||||
list2.push(element.trim());
|
||||
});
|
||||
|
||||
var w = vscode.window.showQuickPick(list2, { "title": "Launch SUV", "placeHolder": "Pick an SUV to launch (e.g. i-012345678)" }).then((value) => {
|
||||
var w = vscode.window.showQuickPick(list2, { "title": "Open SUV in Web Browser", "placeHolder": "Choose an SUV to open" }).then((value) => {
|
||||
if (value !== undefined) {
|
||||
launchSuv(value);
|
||||
}
|
||||
|
||||
30
src/suvManager/SuvManagerTreeDataItem.ts
Normal file
30
src/suvManager/SuvManagerTreeDataItem.ts
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2025 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of mocha-vscode.
|
||||
//
|
||||
// mocha-vscode is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// mocha-vscode is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with mocha-vscode. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class SuvManagerTreeDataItem extends vscode.TreeItem {
|
||||
constructor(label : string) {
|
||||
super(label);
|
||||
|
||||
// this is important, otherwise provideFileDecoration will not be called
|
||||
this.resourceUri = vscode.Uri.parse('x-suv-manager://machines/' + label);
|
||||
|
||||
this.iconPath = "$(database)";
|
||||
this.command = { "command": "mocha.suvmanager.set_selected_item", "title": "Set Selected Item", "arguments": [this] };
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,8 @@ import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import { Machine } from './Machine';
|
||||
import { Machine } from '../Machine';
|
||||
import { SuvManagerTreeDataItem } from './SuvManagerTreeDataItem';
|
||||
|
||||
const cp = require('child_process');
|
||||
|
||||
@ -30,7 +31,7 @@ export class SuvManagerTreeDataProvider implements vscode.TreeDataProvider<Machi
|
||||
|
||||
|
||||
getTreeItem(element: Machine): vscode.TreeItem {
|
||||
return new vscode.TreeItem(element.name);
|
||||
return new SuvManagerTreeDataItem(element.name);
|
||||
}
|
||||
|
||||
getChildren(element?: Machine): Thenable<Machine[]> {
|
||||
@ -42,7 +43,7 @@ export class SuvManagerTreeDataProvider implements vscode.TreeDataProvider<Machi
|
||||
else{
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
cp.exec('mocha suv list', (err: string, stdout: string, stderr: string) =>
|
||||
cp.exec('mocha suv status -f csv', (err: string, stdout: string, stderr: string) =>
|
||||
{
|
||||
let listSuvs = new Array<Machine>();
|
||||
let list = stdout.split('\n');
|
||||
@ -60,13 +61,15 @@ export class SuvManagerTreeDataProvider implements vscode.TreeDataProvider<Machi
|
||||
|
||||
list.forEach( (element) =>
|
||||
{
|
||||
if (element == "")
|
||||
if (element === "")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let fields = element.trim().split(',');
|
||||
|
||||
let m1 = new Machine();
|
||||
m1.name = element.trim();
|
||||
m1.name = fields[0].trim();
|
||||
ct ++;
|
||||
|
||||
listSuvs.push(m1);
|
||||
66
src/suvManager/SuvManagerTreeDecorationProvider.ts
Normal file
66
src/suvManager/SuvManagerTreeDecorationProvider.ts
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright (C) 2025 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of mocha-vscode.
|
||||
//
|
||||
// mocha-vscode is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// mocha-vscode is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with mocha-vscode. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// define the decoration provider
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const cp = require('child_process');
|
||||
|
||||
export class SuvManagerTreeDecorationProvider implements vscode.FileDecorationProvider {
|
||||
provideFileDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<vscode.FileDecoration> {
|
||||
|
||||
let activeSuv = '';
|
||||
|
||||
// https://code.visualstudio.com/api/references/theme-color#lists-and-trees
|
||||
if (uri.scheme === 'x-suv-manager') {
|
||||
let p = uri.path.substring(1);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
cp.exec('mocha suv status -f csv ' + p, (err: string, stdout: string, stderr: string) => {
|
||||
let list = stdout;
|
||||
let details = list.split(',');
|
||||
|
||||
let suvId: string = details[0].trim();
|
||||
let status : string = details[2].trim();
|
||||
|
||||
let cc = new vscode.ThemeColor('disabledForeground');
|
||||
if (status === "stopped") {
|
||||
|
||||
}
|
||||
else if (status === "running") {
|
||||
if (activeSuv === suvId) {
|
||||
cc = new vscode.ThemeColor('gitDecoration.untrackedResourceForeground');
|
||||
}
|
||||
else {
|
||||
cc = new vscode.ThemeColor('foreground');
|
||||
}
|
||||
}
|
||||
|
||||
resolve({
|
||||
// color: new vscode.ThemeColor('list.warningForeground'),
|
||||
color: cc,
|
||||
// badge: "1"
|
||||
tooltip: details[1] + ", " + details[2],
|
||||
badge: details[1][0].toUpperCase()
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user