From 8bb29695ebaea3b927d70f358de0389e6e746249 Mon Sep 17 00:00:00 2001 From: Madang Garden Date: Wed, 18 Sep 2024 17:15:54 +0900 Subject: [PATCH] =?UTF-8?q?feat/#635=20=EC=82=AC=EC=9D=B4=EB=93=9C?= =?UTF-8?q?=EB=B0=94=20=EA=B8=B0=EB=B3=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/package.json | 21 +++++++++++- packages/vscode/src/extension.ts | 5 +++ packages/vscode/src/sidebar.ts | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 packages/vscode/src/sidebar.ts diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 4f383b53..e162dd65 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -28,7 +28,8 @@ "visual analytics" ], "activationEvents": [ - "*" + "*", + "onView:mySidebar" ], "main": "./dist/extension.js", "contributes": { @@ -68,6 +69,24 @@ "description": "Insert your primary color." } } + }, + "viewsContainers": { + "activitybar": [ + { + "id": "mySidebarView", + "title": "My Sidebar", + "icon": "path/to/icon.svg" + } + ] + }, + "views": { + "mySidebarView": [ + { + "type": "webview", + "id": "mySidebar", + "name": "My Sidebar" + } + ] } }, "scripts": { diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index e1c6357f..5afa2914 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -5,6 +5,7 @@ import { COMMAND_LAUNCH, COMMAND_LOGIN_WITH_GITHUB, COMMAND_RESET_GITHUB_AUTH } import { Credentials } from "./credentials"; import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors/ExtensionError"; import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository"; +import { SidebarProvider } from "./sidebar"; import { mapClusterNodesFrom } from "./utils/csm.mapper"; import { findGit, @@ -25,6 +26,10 @@ function normalizeFsPath(fsPath: string) { } export async function activate(context: vscode.ExtensionContext) { + const provider = new SidebarProvider(context.extensionUri); + + context.subscriptions.push(vscode.window.registerWebviewViewProvider("mySidebar", provider)); + const { subscriptions, extensionPath, secrets } = context; const credentials = new Credentials(); let currentPanel: vscode.WebviewPanel | undefined = undefined; diff --git a/packages/vscode/src/sidebar.ts b/packages/vscode/src/sidebar.ts new file mode 100644 index 00000000..d5c3d16f --- /dev/null +++ b/packages/vscode/src/sidebar.ts @@ -0,0 +1,59 @@ +import type * as vscode from "vscode"; + +export class SidebarProvider implements vscode.WebviewViewProvider { + constructor(private readonly _extensionUri: vscode.Uri) {} + + resolveWebviewView(webviewView: vscode.WebviewView) { + webviewView.webview.options = { + enableScripts: true, + }; + + webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); + + webviewView.webview.onDidReceiveMessage(async (data) => { + const result = await this.callApi(data.apiNumber); + webviewView.webview.postMessage({ type: "apiResult", result }); + }); + } + + private async callApi(apiNumber: number): Promise { + // 여기에 실제 API 호출 로직을 구현합니다. + return `API ${apiNumber} 호출 결과`; + } + + private _getHtmlForWebview(webview: vscode.Webview) { + return ` + + + + + + API Caller + + + + + +
+ + + + + `; + } +}