build the structure of the extension

This commit is contained in:
Levi Yan
2024-06-27 01:20:37 +08:00
parent 3fbaa07bee
commit 95b7e3b32d
16 changed files with 1107 additions and 0 deletions

6
src/home.js Normal file
View File

@@ -0,0 +1,6 @@
export default class SIHome {
constructor() {
}
}

80
src/main.js Normal file
View File

@@ -0,0 +1,80 @@
import * as utils from './utils';
import QuickAccessTreeProvider from './views/quick-access-tree';
import vscode from 'vscode';
class SuperIDEExtension {
constructor() {
this.siHome = undefined;
this.context = undefined;
this.subscriptions = [];
}
async activate(context) {
this.context = context;
this.subscriptions.push(
vscode.window.registerTreeDataProvider(
'superide.quickAccess',
new QuickAccessTreeProvider()
)
);
this.registerGlobalCommands();
this.startSuperIDEHome();
}
async startSuperIDEHome() {
vscode.commands.executeCommand('superide.showHome');
}
firstConnect(host, username, password, port, publicKey) {
const ssh = new NodeSSH();
ssh.connect({
host: host,
username: username,
password: password,
port: port
}).then(() => {
console.log('Connected successfully');
ssh.execCommand(`mkdir ~/.ssh &&
touch ~/.ssh/authorized_keys &&
echo ${publicKey} >> ~/.ssh/authorized_keys`, )
.then(result => {
if (result.stdout) console.log('STDOUT: ' + result.stdout);
if (result.stderr) console.log('STDERR: ' + result.stderr);
});
}).catch(error => {
console.log('Error: ', error);
});
}
registerGlobalCommands() {
this.subscriptions.push(
vscode.commands.registerCommand('superide.showHome', (startUrl) =>
this.siHome.toggle(startUrl)
)
);
}
disposeSubscriptions() {
utils.disposeSubscriptions(this.subscriptions);
}
deactivate() {
this.disposeSubscriptions();
}
}
export const extension = new SuperIDEExtension();
export function activate(context) {
extension.activate(context);
return extension;
}
export function deactivate() {
extension.deactivate();
}

5
src/utils.js Normal file
View File

@@ -0,0 +1,5 @@
export function disposeSubscriptions(subscriptions) {
while (subscriptions.length) {
subscriptions.pop().dispose();
}
}

View File

@@ -0,0 +1,44 @@
import * as vscode from 'vscode';
class QuickItem extends vscode.TreeItem {
constructor(label, command, args, collapsibleState, children) {
super(label, collapsibleState);
if (command) {
this.command = {
title: label,
command,
arguments: args,
};
}
this.customChildren = children;
}
}
export default class QuickAccessTreeProvider {
getChildren(element) {
if (element && element.customChildren) {
return element.customChildren;
}
return [
new QuickItem(
'SuperIDE Home',
undefined,
undefined,
vscode.TreeItemCollapsibleState.Expanded,
[new QuickItem('Open', 'superide.showHome')]
),
new QuickItem(
'Miscellaneous',
undefined,
undefined,
vscode.TreeItemCollapsibleState.Expanded,
[new QuickItem('hello', 'superide.hello')]
),
];
}
getTreeItem(element) {
return element;
}
}