338 lines
11 KiB
TypeScript
338 lines
11 KiB
TypeScript
// The module 'vscode' contains the VS Code extensibility API
|
||
// 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 * as path from 'path';
|
||
|
||
import https from 'node:https';
|
||
|
||
const cp = require('child_process');
|
||
|
||
let dpModuleExplorer = new ModuleExplorerTreeDataProvider();
|
||
let treeSuvManager : vscode.TreeView<Machine> | undefined = undefined;
|
||
|
||
export function mkotsuri(suvId : string, tenantName : string, command : string, serviceName : string = "zq", version : string = "v1") : vscode.Uri
|
||
{
|
||
let otsUri = vscode.Uri.parse("https://" + suvId + ".privatesuv.com/ots/" + tenantName + "/services/" + serviceName + "/" + version + "/" + command);
|
||
return otsUri;
|
||
}
|
||
|
||
function updateModuleExplorerTreeView() {
|
||
|
||
dpModuleExplorer.items.push(new GenericTreeDataItem("tools", "tools", [
|
||
new GenericTreeDataItem("tools:xpresso", "xpressO", [
|
||
new GenericTreeDataItem("tools:xpressO:method", "method", [
|
||
new GenericTreeDataItem("tools:xpresso:method:AccessModifier", "AccessModifier", undefined, {
|
||
"type": "class",
|
||
"instanceId": "1$4170"
|
||
}),
|
||
new GenericTreeDataItem("tools:xpresso:method:Method", "Method", undefined, {
|
||
"type": "class",
|
||
"instanceId": "1$4171"
|
||
})
|
||
], {
|
||
"type": "module"
|
||
})
|
||
], {
|
||
"type": "module"
|
||
})],
|
||
{
|
||
"type": "module"
|
||
}
|
||
));
|
||
return;
|
||
|
||
let suvId : string = "i-0c0398f84acecb702";
|
||
let tenantName : string = "super";
|
||
let otsuri = mkotsuri(suvId, tenantName, "module/list");
|
||
|
||
cp.exec("curl " + otsuri.toString(), (err: string, stdout: string, stderr: string) =>
|
||
{
|
||
if (err != "")
|
||
{
|
||
vscode.window.showErrorMessage(err);
|
||
}
|
||
let json = JSON.parse(stdout);
|
||
for (var i = 0; i < json.items.length; i++)
|
||
{
|
||
recursiveAddItemToTreeView(dpModuleExplorer, json.items[i], null);
|
||
}
|
||
|
||
dpModuleExplorer.refresh();
|
||
|
||
//let treeModuleExplorer = vscode.window.createTreeView("mocha.moduleExplorer", { "canSelectMany": true, "showCollapseAll": true, "treeDataProvider": dpModuleExplorer });
|
||
//console.log(stdout);
|
||
});
|
||
}
|
||
|
||
function recursiveAddItemToTreeView(dp : GenericTreeDataProvider, item : any, parent : GenericTreeDataItem | null)
|
||
{
|
||
var p;
|
||
if (item.instanceId)
|
||
{
|
||
p = new GenericTreeDataItem(item.name, item.title, undefined, { "type": item.type, "instanceId": item.instanceId });
|
||
}
|
||
else
|
||
{
|
||
p = new GenericTreeDataItem(item.name, item.title, undefined, { "type": item.type });
|
||
}
|
||
if (item.items)
|
||
{
|
||
for (var i = 0; i < item.items.length; i++)
|
||
{
|
||
recursiveAddItemToTreeView(dp, item.items[i], p);
|
||
}
|
||
}
|
||
if (parent === null)
|
||
{
|
||
console.log("adding item '" + p.name + "' to root");
|
||
dp.items.push(p);
|
||
}
|
||
else
|
||
{
|
||
console.log("adding item '" + p.name + "' to parent '" + parent.name + "'");
|
||
parent.children.push(p);
|
||
}
|
||
}
|
||
|
||
function launchSuv(name : string)
|
||
{
|
||
cp.exec("mocha suv up " + name, (err2: string, stdout2: string, stderr2: string) => {
|
||
vscode.window.showInformationMessage('Selected SUV ( ' + name + ' ) launched successfully!');
|
||
});
|
||
vscode.window.showInformationMessage('Selected SUV ( ' + name + ' ) is launching now!');
|
||
}
|
||
|
||
let outputChannel: vscode.OutputChannel | undefined = undefined;
|
||
|
||
export function openWebBrowser(url: vscode.Uri) {
|
||
|
||
cp.exec("xdg-open " + url.toString(), (err: string, stdout: string, stderr: string) => {
|
||
});
|
||
}
|
||
|
||
// This method is called when your extension is activated
|
||
// Your extension is activated the very first time the command is executed
|
||
export function activate(context: vscode.ExtensionContext) {
|
||
|
||
outputChannel = vscode.window.createOutputChannel("Mocha");
|
||
outputChannel.appendLine("Mocha for VSCode activated");
|
||
|
||
let treeDataProvider = new SuvManagerTreeDataProvider();
|
||
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 });
|
||
// dpModuleExplorer.treeview = treeModuleExplorer;
|
||
// treeModuleExplorer.badge = { "value": 1, "tooltip": "1 SUV(s) running" };
|
||
|
||
updateModuleExplorerTreeView();
|
||
|
||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||
// This line of code will only be executed once when your extension is activated
|
||
console.log('Congratulations, your extension "suvmanager" is now active!');
|
||
|
||
let cmd_zq_import_function_signature = vscode.commands.registerCommand("mocha.zq_import_function_signature", () => {
|
||
/*
|
||
const rootCas = require('ssl-root-cas').create();
|
||
rootCas.addFile(path.resolve(__dirname, 'localhost.crt'));
|
||
https.globalAgent.options.ca = rootCas;
|
||
let req = https.request({
|
||
"hostname": otsuri.authority,
|
||
"port": 443,
|
||
"path": otsuri.path,
|
||
"method": "GET",
|
||
"headers":
|
||
{
|
||
}
|
||
}, (res) => {
|
||
res.on("data", (chunk) => {
|
||
console.log("BODY: " + chunk);
|
||
});
|
||
res.on("end", () => {
|
||
console.log("end transmission");
|
||
});
|
||
});
|
||
|
||
req.on('error', (e) => {
|
||
console.error(`problem with request: ${e.message}`);
|
||
});
|
||
|
||
req.end();
|
||
|
||
*/
|
||
|
||
vscode.window.showQuickPick([ "Access Modifier@get Access Modifier.for Metadata With Access Modifier(GR)",
|
||
"Access Modifier@get Access Modifiers Effectively Equivalent to A2 Root Acess(GSI)*S",
|
||
"Access Modifier@get Access Modifiers with Override Restrictions(GSI)*S",
|
||
"Access Modifier@get Active Method Accesses(IOP)*S",
|
||
"Access Modifier@get Method Access Public Instance(GSI)*S(public)",
|
||
"Access Modifier@get Methods for Access Modifiers(IOP)*P*S",
|
||
"Access Modifier@get Most Restrictive from Set(SS)*P*S"], { title: "Function name or instance ID"}).then ((choice) =>
|
||
{
|
||
let ed = vscode.window.activeTextEditor;
|
||
if (ed !== undefined)
|
||
{
|
||
ed.edit((edit) => {
|
||
|
||
if (ed !== undefined)
|
||
{
|
||
if (choice !== undefined)
|
||
{
|
||
var ppp = choice.split("@");
|
||
var qqq = ppp[1].replaceAll(" ", "").replaceAll(".", "");
|
||
var xxx = qqq.substring(0, qqq.indexOf('('));
|
||
|
||
edit.insert(ed.selection.active, "static stub function " + xxx + "() : AccessModifier");
|
||
}
|
||
}
|
||
|
||
});
|
||
}
|
||
|
||
});
|
||
|
||
});
|
||
|
||
let cmd_mocha_open_doc = vscode.commands.registerCommand("mocha.zq_open_document", (item : GenericTreeDataItem) => {
|
||
|
||
console.log(item.name);
|
||
|
||
if (item.customAttributes["instanceId"])
|
||
{
|
||
let tdi = vscode.workspace.openTextDocument(vscode.Uri.file(path.join(userInfo().homedir, item.title + ".zql") ).with({ scheme: "untitled" })).then( (doc) =>
|
||
{
|
||
vscode.window.showTextDocument(doc).then((editor) =>
|
||
{
|
||
editor.edit(edit => {
|
||
edit.delete(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(editor.document.lineCount - 1, editor.document.lineAt(editor.document.lineCount-1).range.end.character)))
|
||
|
||
edit.insert(new vscode.Position(0, 0), "class " + item.title + ", " + item.customAttributes["instanceId"] + " {\n\nattributes:\n name: 4$1 : text\n order, 4$7 : text\n\nrelationships:\n forMetadataWithAccessModifier, 3$11854\n\nfunctions:\n\ninstances:\n Public, 4170$1\n}");
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
});
|
||
|
||
// The command has been defined in the package.json file
|
||
// Now provide the implementation of the command with registerCommand
|
||
// The commandId parameter must match the command field in package.json
|
||
let cmd_suv_manager = vscode.commands.registerCommand('mocha.suvmanager.suv_manager', () => {
|
||
// The code you place here will be executed every time your command is executed
|
||
// Display a message box to the user
|
||
|
||
vscode.window.showInformationMessage('Add code here to display SUV Manager panel!');
|
||
});
|
||
context.subscriptions.push(cmd_suv_manager);
|
||
|
||
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) => {
|
||
vscode.window.showInformationMessage(stdout);
|
||
let list = stdout.split(' ');
|
||
let list2 = new Array<string>();
|
||
list.forEach((element) => {
|
||
list2.push(element.trim());
|
||
});
|
||
|
||
var w = vscode.window.showQuickPick(list2, { "title": "Open SUV in Web Browser", "placeHolder": "Choose an SUV to open" }).then((value) => {
|
||
if (value !== undefined) {
|
||
openWebBrowser(vscode.Uri.parse("https://" + value + ".privatesuv.com"));
|
||
}
|
||
});
|
||
});
|
||
}
|
||
else
|
||
{
|
||
let machine : Machine = args[0] as Machine;
|
||
openWebBrowser(vscode.Uri.parse("https://" + machine.name + ".privatesuv.com"));
|
||
}
|
||
});
|
||
|
||
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 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) => {
|
||
if (value !== undefined) {
|
||
launchSuv(value);
|
||
}
|
||
});
|
||
});
|
||
}
|
||
else
|
||
{
|
||
let machine : Machine = args[0] as Machine;
|
||
launchSuv(machine.name);
|
||
}
|
||
});
|
||
|
||
let cmd_suv_new = vscode.commands.registerCommand('mocha.suvmanager.suv_new', () => {
|
||
outputChannel?.appendLine("Provisioning a new persistent SUV...");
|
||
|
||
cp.exec('mocha suv new --unattended', (err: string, stdout: string, stderr: string) =>
|
||
{
|
||
if (err == null) {
|
||
outputChannel?.appendLine("New SUV provisioned successfully!");
|
||
|
||
vscode.window.showInformationMessage('New SUV provisioned successfully!');
|
||
}
|
||
else {
|
||
outputChannel?.appendLine(err);
|
||
vscode.window.showErrorMessage("SUV provisioning failed. Check the error log for details.", "Show Error Log").then((value) => {
|
||
if (value == "Show Error Log")
|
||
{
|
||
outputChannel?.show();
|
||
}
|
||
});
|
||
}
|
||
treeDataProvider.refresh();
|
||
});
|
||
});
|
||
context.subscriptions.push(cmd_suv_up);
|
||
}
|
||
|
||
// This method is called when your extension is deactivated
|
||
export function deactivate() {}
|
||
|
||
/*
|
||
|
||
// This method is called when your extension is activated
|
||
// Your extension is activated the very first time the command is executed
|
||
export function activate(context: vscode.ExtensionContext) {
|
||
|
||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||
// This line of code will only be executed once when your extension is activated
|
||
console.log('Blah blah the blah blah!');
|
||
|
||
// The command has been defined in the package.json file
|
||
// Now provide the implementation of the command with registerCommand
|
||
// The commandId parameter must match the command field in package.json
|
||
const disposable = vscode.commands.registerCommand('mocha-vscode.helloWorld', () => {
|
||
// The code you place here will be executed every time your command is executed
|
||
// Display a message box to the user
|
||
vscode.window.showInformationMessage('Blah blah the blah blah!');
|
||
});
|
||
|
||
context.subscriptions.push(disposable);
|
||
}
|
||
|
||
// This method is called when your extension is deactivated
|
||
export function deactivate() {}
|
||
*/ |