-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> { | ||
// 여기에 실제 API 호출 로직을 구현합니다. | ||
return `API ${apiNumber} 호출 결과`; | ||
} | ||
|
||
private _getHtmlForWebview(webview: vscode.Webview) { | ||
return ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>API Caller</title> | ||
</head> | ||
<body> | ||
<button onclick="callApi(1)">API 1</button> | ||
<button onclick="callApi(2)">API 2</button> | ||
<button onclick="callApi(3)">API 3</button> | ||
<div id="result"></div> | ||
<script> | ||
const vscode = acquireVsCodeApi(); | ||
function callApi(apiNumber) { | ||
vscode.postMessage({ type: 'apiCall', apiNumber }); | ||
} | ||
window.addEventListener('message', event => { | ||
const message = event.data; | ||
switch (message.type) { | ||
case 'apiResult': | ||
document.getElementById('result').innerText = message.result; | ||
break; | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
} |