Skip to content

Commit

Permalink
Merge pull request #5 from Weminal-labs/develop
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
tung-lee authored Mar 24, 2024
2 parents 1abd187 + dedc9fc commit 20d67a4
Show file tree
Hide file tree
Showing 12 changed files with 656 additions and 195 deletions.
1 change: 1 addition & 0 deletions media/tools.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sui-simulator-vscode",
"displayName": "sui-simulator-vscode",
"description": "",
"version": "0.0.1",
"version": "0.2.0",
"engines": {
"vscode": "^1.87.0"
},
Expand All @@ -12,6 +12,26 @@
"activationEvents": [],
"main": "./dist/extension.js",
"contributes": {
"viewsContainers": {
"activitybar": [
{
"id": "sui-simulator-sidebar-view",
"title": "Sui Simulator",
"icon": "media/tools.svg"
}
]
},
"views": {
"sui-simulator-sidebar-view": [
{
"type": "webview",
"id": "sui-simulator-sidebar",
"name": "Sui Simulator",
"icon": "media/tools.svg",
"contextualTitle": "Sui Simulator"
}
]
},
"commands": [
{
"command": "sui-simulator-vscode.helloWorld",
Expand Down Expand Up @@ -75,4 +95,4 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
}
}
}
79 changes: 79 additions & 0 deletions src/SidebarProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as vscode from "vscode";
import { build, executeCommand, publish } from "./suiCommand";
import { join } from "path";

export class SidebarProvider implements vscode.WebviewViewProvider {
constructor(private readonly _extensionContext: vscode.ExtensionContext) { }

public resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext, token: vscode.CancellationToken) {

webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,

localResourceRoots: [this._extensionContext.extensionUri],
};

webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);

webviewView.webview.onDidReceiveMessage((message) => {
const { command, requestId, payload } = message;

switch (command) {
case "SUI_TERMINAL":
executeCommand(payload.command, payload.suiPath);
break;

case "BUILD":
build(payload.packagePath, payload.suiPath);
break;

case "PUBLISH":
publish(payload.packagePath, payload.suiPath);
break;

case "SAVE_ALIASES":
this._extensionContext.workspaceState.update(payload.address, {
aliases: payload.aliases
}).then(() => {
vscode.window.showInformationMessage("Aliases saved successfully!");
});

// use value as undefined to remove the key
// context.workspaceState.update("", undefined);

default:
vscode.window.showInformationMessage(`Unknown command: ${command}`);
}
});
}

private _getHtmlForWebview(webview: vscode.Webview) {
const jsFile = "webview.js";
const localServerUrl = "http://localhost:9999";

let scriptUrl = null;
let cssUrl = null;

const isProduction = this._extensionContext.extensionMode === vscode.ExtensionMode.Production;
if (isProduction) {
scriptUrl = webview.asWebviewUri(vscode.Uri.file(join(this._extensionContext.extensionPath, 'dist', jsFile))).toString();
} else {
scriptUrl = `${localServerUrl}/${jsFile}`;
}

return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${isProduction ? `<link href="${cssUrl}" rel="stylesheet">` : ''}
</head>
<body>
<div id="root"></div>
<script src="${scriptUrl}"></script>
</body>
</html>`;
}
}
20 changes: 20 additions & 0 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export enum MoveCallStatus {
BEGIN,
FINISH,
ERROR,
};

export enum MoveCallActionType {
SET_MNEMONICS = "SET_MNEMONICS",
SET_PACKAGE_ID = "SET_PACKAGE_ID",
SET_MODULES = "SET_MODULES",
SET_ERROR = "SET_ERROR",
SET_CURRENT_MODULE = "SET_CURRENT_MODULE",
SET_FUNCTIONS = "SET_FUNCTIONS",
SET_CURRENT_FUNCTION = "SET_CURRENT_FUNCTION",
RESET_ARGS = "RESET_ARGS",
RESET_ARGS_USER_INPUT = "RESET_ARGS_USER_INPUT",
ADD_ARG = "ADD_ARG",
SET_VALUE_TO_ARG = "SET_VALUE_TO_ARG",
SET_RESPONSE = "SET_RESPONSE",
};
15 changes: 12 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as vscode from 'vscode';
import { join } from 'path';
import { MessageHandlerData } from '@estruyf/vscode';
import { build, publish, executeCommand } from './suiCommand';
import { SidebarProvider } from './SidebarProvider';

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand All @@ -22,6 +23,14 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.showInformationMessage('Hello World from sui-simulator-vscode!');
});

const sidebarProvider = new SidebarProvider(context);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
"sui-simulator-sidebar",
sidebarProvider
)
);

context.subscriptions.push(disposable);

context.subscriptions.push(vscode.commands.registerCommand("sui-simulator-vscode.webView", () => {
Expand Down Expand Up @@ -64,15 +73,15 @@ export function activate(context: vscode.ExtensionContext) {
break;

case "SUI_TERMINAL":
executeCommand(payload.command);
executeCommand(payload.command, payload.suiPath);
break;

case "BUILD":
build(payload.path);
build(payload.packagePath, payload.suiPath);
break;

case "PUBLISH":
publish(payload.path);
publish(payload.packagePath, payload.suiPath);
break;

case "SAVE_ALIASES":
Expand Down
22 changes: 16 additions & 6 deletions src/suiCommand.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import * as vscode from 'vscode';

export const build = (path: string) => {
const handleSuiPathEmpty = (suiPath: string) => {
if (!suiPath) {
return "sui";
}
return suiPath;
}

export const build = (path: string, suiPath: string) => {
suiPath = handleSuiPathEmpty(suiPath);
const terminal = vscode.window.createTerminal("Sui Simulator");
terminal.sendText(`sui move build -p ${path}`);
terminal.sendText(`${suiPath} move build -p ${path}`);
terminal.show();
};

export const publish = (path: string) => {
export const publish = (path: string, suiPath: string) => {
suiPath = handleSuiPathEmpty(suiPath);
const terminal = vscode.window.createTerminal("Sui Simulator");
terminal.sendText(`sui client publish --gas-budget 100000000 ${path}`);
terminal.sendText(`${suiPath} client publish --gas-budget 100000000 ${path}`);
terminal.show();
};

export const executeCommand = (command: string) => {
export const executeCommand = (command: string, suiPath: string) => {
suiPath = handleSuiPathEmpty(suiPath);
const terminal = vscode.window.createTerminal("Sui Simulator");
terminal.sendText(command);
terminal.sendText(`${suiPath} ${command}`);
terminal.show();
};
23 changes: 23 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SuiMoveNormalizedFunction } from "@mysten/sui.js/client";
import { MoveCallStatus } from "../enums";

export interface ActionType {
type: string,
payload: any
};

export interface MoveCallState {
mnemonics: string,
status: MoveCallStatus,
packageId: string,
modules: string[],
currentModule: string,
functions: {
[key: string]: SuiMoveNormalizedFunction;
},
currentFunction: string;
args: string[],
argsUserInput: string[],
error: string,
response: string,
}
Loading

0 comments on commit 20d67a4

Please sign in to comment.